Aggiungi 'craplog/scr/main/java/crapcode/crapnote.java'

This commit is contained in:
Valentino Orlandi 2022-06-11 21:57:37 +00:00
parent a4152f7bdd
commit 5adc0b6aa7

View file

@ -0,0 +1,299 @@
package crapcode;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.event.KeyEvent;
import java.io.InputStream;
import java.io.IOException;
public class crapnote extends javax.swing.JFrame {
String font_path;
Font font;
float font_size;
public crapnote() {
initComponents();
this.font_size = 15f;
try {
InputStream fs = getClass().getResourceAsStream("/fonts/Metropolis.ttf");
this.font = Font.createFont( Font.TRUETYPE_FONT, fs );
} catch (FontFormatException | IOException e) {
System.out.println("Unable to load font: 'Metropolis.ttf'");
}
this.font = this.font.deriveFont( Font.PLAIN, this.font_size );
this.jTextFieldSIZE.setText( String.format("%.0f",this.font_size) );
this.jTextPaneBLOCK.setFont( this.font );
}
/**
* 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() {
jPanelNOTE = new javax.swing.JPanel();
jPanelZOOM = new javax.swing.JPanel();
jPanelZOOMmain = new javax.swing.JPanel();
jButtonMINUM = new javax.swing.JButton();
jButtonPLUS = new javax.swing.JButton();
jTextFieldSIZE = new javax.swing.JTextField();
jPanelZOOMpadl = new javax.swing.JPanel();
jPanelZOOMpadr = new javax.swing.JPanel();
jScrollPaneBLOCK = new javax.swing.JScrollPane();
jTextPaneBLOCK = new javax.swing.JTextPane();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setBackground(new java.awt.Color(30, 30, 30));
setMinimumSize(new java.awt.Dimension(156, 128));
setName("frameNOTE"); // NOI18N
setPreferredSize(new java.awt.Dimension(512, 512));
jPanelNOTE.setBackground(new java.awt.Color(255, 238, 119));
jPanelNOTE.setMinimumSize(new java.awt.Dimension(160, 128));
jPanelNOTE.setPreferredSize(new java.awt.Dimension(512, 512));
jPanelZOOM.setBackground(new java.awt.Color(0, 0, 0));
jPanelZOOM.setMinimumSize(new java.awt.Dimension(160, 56));
jPanelZOOM.setPreferredSize(new java.awt.Dimension(512, 56));
jPanelZOOMmain.setBackground(new java.awt.Color(0, 0, 0));
jButtonMINUM.setBackground(new java.awt.Color(23, 23, 23));
jButtonMINUM.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/less.png"))); // NOI18N
jButtonMINUM.setMaximumSize(new java.awt.Dimension(32, 32));
jButtonMINUM.setMinimumSize(new java.awt.Dimension(32, 32));
jButtonMINUM.setPreferredSize(new java.awt.Dimension(32, 32));
jButtonMINUM.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonMINUMActionPerformed(evt);
}
});
jButtonPLUS.setBackground(new java.awt.Color(23, 23, 23));
jButtonPLUS.setFont(new java.awt.Font("Metropolis", 0, 13)); // NOI18N
jButtonPLUS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/more.png"))); // NOI18N
jButtonPLUS.setMaximumSize(new java.awt.Dimension(32, 32));
jButtonPLUS.setMinimumSize(new java.awt.Dimension(32, 32));
jButtonPLUS.setPreferredSize(new java.awt.Dimension(32, 32));
jButtonPLUS.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonPLUSActionPerformed(evt);
}
});
jTextFieldSIZE.setFont(new java.awt.Font("Metropolis", 1, 15)); // NOI18N
jTextFieldSIZE.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextFieldSIZE.setText("100");
jTextFieldSIZE.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jTextFieldSIZEKeyPressed(evt);
}
});
javax.swing.GroupLayout jPanelZOOMmainLayout = new javax.swing.GroupLayout(jPanelZOOMmain);
jPanelZOOMmain.setLayout(jPanelZOOMmainLayout);
jPanelZOOMmainLayout.setHorizontalGroup(
jPanelZOOMmainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelZOOMmainLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jButtonMINUM, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextFieldSIZE, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonPLUS, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanelZOOMmainLayout.setVerticalGroup(
jPanelZOOMmainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelZOOMmainLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanelZOOMmainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButtonPLUS, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButtonMINUM, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextFieldSIZE, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
jPanelZOOMpadl.setBackground(new java.awt.Color(0, 0, 0));
javax.swing.GroupLayout jPanelZOOMpadlLayout = new javax.swing.GroupLayout(jPanelZOOMpadl);
jPanelZOOMpadl.setLayout(jPanelZOOMpadlLayout);
jPanelZOOMpadlLayout.setHorizontalGroup(
jPanelZOOMpadlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
jPanelZOOMpadlLayout.setVerticalGroup(
jPanelZOOMpadlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
jPanelZOOMpadr.setBackground(new java.awt.Color(0, 0, 0));
javax.swing.GroupLayout jPanelZOOMpadrLayout = new javax.swing.GroupLayout(jPanelZOOMpadr);
jPanelZOOMpadr.setLayout(jPanelZOOMpadrLayout);
jPanelZOOMpadrLayout.setHorizontalGroup(
jPanelZOOMpadrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
jPanelZOOMpadrLayout.setVerticalGroup(
jPanelZOOMpadrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanelZOOMLayout = new javax.swing.GroupLayout(jPanelZOOM);
jPanelZOOM.setLayout(jPanelZOOMLayout);
jPanelZOOMLayout.setHorizontalGroup(
jPanelZOOMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelZOOMLayout.createSequentialGroup()
.addComponent(jPanelZOOMpadl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanelZOOMmain, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanelZOOMpadr, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanelZOOMLayout.setVerticalGroup(
jPanelZOOMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelZOOMLayout.createSequentialGroup()
.addGroup(jPanelZOOMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jPanelZOOMpadl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanelZOOMmain, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jPanelZOOMpadr, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE))
);
jScrollPaneBLOCK.setPreferredSize(new java.awt.Dimension(432, 488));
jTextPaneBLOCK.setBackground(new java.awt.Color(255, 238, 119));
jTextPaneBLOCK.setFont(new java.awt.Font("Metropolis", 0, 15)); // NOI18N
jScrollPaneBLOCK.setViewportView(jTextPaneBLOCK);
javax.swing.GroupLayout jPanelNOTELayout = new javax.swing.GroupLayout(jPanelNOTE);
jPanelNOTE.setLayout(jPanelNOTELayout);
jPanelNOTELayout.setHorizontalGroup(
jPanelNOTELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelNOTELayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPaneBLOCK, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE)
.addContainerGap())
.addComponent(jPanelZOOM, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPanelNOTELayout.setVerticalGroup(
jPanelNOTELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelNOTELayout.createSequentialGroup()
.addComponent(jPanelZOOM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPaneBLOCK, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanelNOTE, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanelNOTE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButtonPLUSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPLUSActionPerformed
// increase text size
this.font_size += 1;
this.font = this.font.deriveFont( this.font_size );
this.jTextFieldSIZE.setText( String.format("%.0f",this.font_size) );
this.jTextPaneBLOCK.setFont( this.font );
// disable if size is > 0
if (this.font_size > 0
&& this.jButtonMINUM.isEnabled() == false
) {
this.jButtonMINUM.setEnabled(true);
}
}//GEN-LAST:event_jButtonPLUSActionPerformed
private void jButtonMINUMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMINUMActionPerformed
// reduce text size
this.font_size -= 1;
this.font = this.font.deriveFont( this.font_size );
this.jTextFieldSIZE.setText( String.format("%.0f",this.font_size) );
this.jTextPaneBLOCK.setFont( this.font );
// disable if size is 0
if ( this.font_size == 0 ) {
this.jButtonMINUM.setEnabled(false);
}
}//GEN-LAST:event_jButtonMINUMActionPerformed
private void jTextFieldSIZEKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldSIZEKeyPressed
// set the selected size
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
this.font_size = Float.parseFloat( this.jTextFieldSIZE.getText() );
if ( this.font_size < 0 ) {
this.font_size = 0;
this.jButtonMINUM.setEnabled(false);
}
this.font = this.font.deriveFont( this.font_size );
this.jTextFieldSIZE.setText( String.format("%.0f",this.font_size) );
this.jTextPaneBLOCK.setFont( this.font );
}
}//GEN-LAST:event_jTextFieldSIZEKeyPressed
/**
* @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 code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(crapnote.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(crapnote.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(crapnote.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(crapnote.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new crapnote().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonMINUM;
private javax.swing.JButton jButtonPLUS;
private javax.swing.JPanel jPanelNOTE;
private javax.swing.JPanel jPanelZOOM;
private javax.swing.JPanel jPanelZOOMmain;
private javax.swing.JPanel jPanelZOOMpadl;
private javax.swing.JPanel jPanelZOOMpadr;
private javax.swing.JScrollPane jScrollPaneBLOCK;
private javax.swing.JTextField jTextFieldSIZE;
private javax.swing.JTextPane jTextPaneBLOCK;
// End of variables declaration//GEN-END:variables
}