/*
* Testform.java
*
* Created on 5. Januar 2007, 09:42
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.JList;
import java.util.Vector;
import javax.swing.*;
import javax.swing.text.*;
import java.util.Comparator;
import java.util.Arrays;
/**
*
* @author Markus
*/
public class Testform extends javax.swing.JFrame {
/** Creates new form Testform */
public Testform() {
setFocusable(true);
initComponents();
Tastendruck();
}
public String CurrSong;
public int songs = 1;
public int CountPos = 0;
public String songtext ="";
public String SongPart ="";
public String SongX="";
public String SongSuff1="\n";
public String SongSuff2="";
public int SongEnd;
public int SongPos;
public Vector<Object> zeilen = new Vector<Object>();
public SimpleAttributeSet GrossGrau = new SimpleAttributeSet();
public SimpleAttributeSet GrossSchwarz = new SimpleAttributeSet();
public void getSong(int SongID)
{
File path = new File( "Texte/" );
File files[] = path.listFiles(new FilenameFilter() {
public boolean accept(File d, String name) { return name.endsWith(".txt"); }});
songs = files.length;
Arrays.sort(files, 0, songs);
CurrSong = files[SongID].getPath();
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(0, 51, 51));
setForeground(java.awt.Color.black);
jButton1.setText("Exit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jScrollPane1.setWheelScrollingEnabled(false);
jTextPane1.setBackground(new java.awt.Color(0, 0, 0));
jTextPane1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jTextPane1.setFont(new java.awt.Font("Tahoma", 0, 50));
jTextPane1.setForeground(new java.awt.Color(255, 255, 255));
jTextPane1.setText("Text1");
jTextPane1.setAutoscrolls(false);
jScrollPane1.setViewportView(jTextPane1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(315, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[])
throws Exception
{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Testform t = new Testform();
t.setVisible(true);
}
});
}
public void Tastendruck() {
this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
jTextPane1.setText("\nUse arrow keys to navigate:\n\n" +
"LEFT, RIGHT:\nPrevious/next Song\n\nUP, DOWN:\nScroll within Song" +
"\n\n\nStart by clicking RIGHT arrow key!");
addKeyListener(
new KeyAdapter() {
public void keyPressed(KeyEvent event)
{
SongPart ="";
jTextPane1.setText(SongPart);
if (event.getKeyCode() == KeyEvent.VK_LEFT) {
SongPos = 0;
if (CountPos == 1)
{CountPos=songs;}
else if (CountPos == 0)
{CountPos=songs;}
else
{CountPos=CountPos-1;}
getSong(CountPos-1);
zeilen.clear();
ReadSong(CurrSong);
SongPos=0;
for (int i = 1; i < 12; i++) {
FormZeile(SongPos,SongSuff1, i);
SongPos=i;
}
FormZeile(SongPos,SongSuff2, 77);
SongPart = SongPart + zeilen.elementAt(SongPos);
jTextPane1.setCaretPosition(0);
SongPos=SongPos-1;
}
if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
SongPos = 0;
if (songs == 1)
{
CountPos=1;
}
if (songs == CountPos)
{
CountPos=1;
}
else
{
CountPos=CountPos+1;
}
getSong(CountPos-1);
zeilen.clear();
ReadSong(CurrSong);
SongPos=0;
for (int i = 1; i < 12; i++) {
FormZeile(SongPos,SongSuff1, i);
SongPos=i;
}
FormZeile(SongPos,SongSuff2, 77);
SongPart = SongPart + zeilen.elementAt(SongPos);
jTextPane1.setCaretPosition(0);
SongPos=SongPos-1;
}
if (event.getKeyCode() == KeyEvent.VK_DOWN) {
for (int i = 1; i < 12; i++) {
if (SongPos >= zeilen.size()){
zeilen.add("");
}
FormZeile(SongPos,SongSuff1, i);
SongPos = SongPos+1;
if (SongPos >= zeilen.size()){
zeilen.add("");
}
}
FormZeile(SongPos,SongSuff2, 77);
jTextPane1.setCaretPosition(0);
SongPos=SongPos-1;
}
if (event.getKeyCode() == KeyEvent.VK_UP) {
SongPos=SongPos-20;
for (int i = 1; i < 12; i++) {
if (SongPos <0){
SongPos=0;
}
FormZeile(SongPos,SongSuff1, i);
SongPos = SongPos+1;
}
FormZeile(SongPos,SongSuff2, 77);
jTextPane1.setCaretPosition(0);
SongPos=SongPos-1;
}
}
}
);
}
public void ReadSong(String SongToRead)
{
try{
BufferedReader br =
new BufferedReader(new FileReader(SongToRead));
String zeile = br.readLine();
int CurrZeile = 0;
while(zeile != null) {
songtext = songtext + zeile + "\n";
zeilen.add(zeile);
zeile = br.readLine();
CurrZeile++;
}
}catch(IOException ioe){
ioe.printStackTrace();
}
System.out.println(songtext);
System.out.println("Titel: " + zeilen.elementAt(0));
songtext = "";
SongEnd = zeilen.size();
System.out.println("Zeilenzahl: "+String.valueOf(SongEnd));
}
public void FormZeile (int ZeilenNum, String Suffix, int I){
//System.out.println("ZeilenNum: "+String.valueOf(ZeilenNum));
//System.out.println("I: "+String.valueOf(I));
StyledDocument doc2 = jTextPane1.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc2.setParagraphAttributes(0, doc2.getLength(), center, false);
StyleConstants.setForeground(GrossGrau, Color.DARK_GRAY);
StyleConstants.setForeground(GrossSchwarz, Color.WHITE);
try {
SongX = (String) zeilen.elementAt(ZeilenNum)+Suffix;
if (I == 77 || I ==1 && ZeilenNum != 0){
doc2.insertString(doc2.getLength(), SongX,GrossGrau);
}
else if (ZeilenNum == 0 && I ==1){
doc2.insertString(doc2.getLength(), SongX,GrossSchwarz);
}
else{
doc2.insertString(doc2.getLength(), SongX,GrossSchwarz);
}
} catch (BadLocationException ex) {
ex.printStackTrace();
}
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextPane jTextPane1;
// End of variables declaration
}