/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* DisplayJframe.java
*
* Created on 18.10.2011, 17:29:08
*/
package cleaningrobot.GUI;
import java.util.Timer;
import java.util.TimerTask;
import cleaningrobot.Facade.Facade;
/**
*
*
*/
public class OperatingPanel extends javax.swing.JFrame {
//Objekterzeugung
protected int k = 0;
protected int lastIndex = 0;
protected int secondLastIndex = 0;
protected int thirdLastIndex = 0;
protected int startTime = 0;
protected int startMinute = 0;
protected int count = 0;
protected int count2 = 0;
protected int temp = 0;
protected int i = 0;
protected Object mode;
private int[] startZeit = new int [2];
public RobotDisplayModel mainMenu;
public RobotDisplayModel startTimeMinute;
public RobotDisplayModel startTimeHour;
public RobotDisplayModel quickStart;
public RobotDisplayModel cleanSettings;
public RobotDisplayModel showEntry;
public RobotDisplayModel deleteEntry;
public RobotDisplayModel offModel;
/** Creates new form DisplayJframe */
public OperatingPanel() {
initComponents();
mainMenu = new RobotDisplayModel("Hauptmenü", "Jetzt reinigen", "Reinigung hinzufügen", "Reinigungszeit anzeigen", "Reinigung löschen");
startTimeHour = new RobotDisplayModel("Startzeit (Stunde)", "0 h", "1 h", "2 h", "3 h", "4 h", "5 h", "6 h", "7 h", "8 h", "9 h", "10 h", "11 h", "12 h", "13 h", "14 h", "15 h", "16 h", "17 h", "18 h", "19 h", "20 h", "21 h", "22 h", "23 h");
startTimeMinute = new RobotDisplayModel("Startzeit (Minute)", "0 m", "10 m", "20 m", "30 m", "40 m", "50 m");
quickStart = new RobotDisplayModel("Reinigungszeit", "10 m", "20 m", "30 m", "40 m", "50 m");
cleanSettings = new RobotDisplayModel("Modus/Beleuchtung", "Eco Tag", "Eco Nacht", "Intensiv Tag", "Intensiv Nacht");
showEntry = new RobotDisplayModel("Reinigungszeit anzeigen", "Keine Reinigungszeit vorhanden");
deleteEntry = new RobotDisplayModel("Reinigungszeiten löschen", "Keine Reinigungszeit vorhanden");
offModel = new RobotDisplayModel();
listMenu.setModel(offModel);
}
/** 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">
private void initComponents() {
upButton = new javax.swing.JButton();
rightButton = new javax.swing.JButton();
leftButton = new javax.swing.JButton();
downButton = new javax.swing.JButton();
okButton = new javax.swing.JButton();
onOff_Button = new javax.swing.JToggleButton();
scrollPane = new javax.swing.JScrollPane();
listMenu = new javax.swing.JList();
progressBar = new javax.swing.JProgressBar();
emptyButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
formComponentResized(evt);
}
});
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cleaningrobot/Container/up-arrow-icon-md.png"))); // NOI18N
upButton.setEnabled(false);
upButton.setPreferredSize(new java.awt.Dimension(80, 40));
upButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
upButtonActionPerformed(evt);
}
});
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cleaningrobot/Container/right-arrow-icon-md.png"))); // NOI18N
rightButton.setEnabled(false);
rightButton.setPreferredSize(new java.awt.Dimension(40, 40));
rightButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rightButtonActionPerformed(evt);
}
});
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cleaningrobot/Container/left-arrow-icon-md.png"))); // NOI18N
leftButton.setEnabled(false);
leftButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
leftButtonActionPerformed(evt);
}
});
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cleaningrobot/Container/down-arrow-icon-md.png"))); // NOI18N
downButton.setEnabled(false);
downButton.setPreferredSize(new java.awt.Dimension(40, 40));
downButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
downButtonActionPerformed(evt);
}
});
okButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cleaningrobot/Container/ok-icon-md.png"))); // NOI18N
okButton.setEnabled(false);
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
onOff_Button.setText("On/Off");
onOff_Button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onOff_ButtonActionPerformed(evt);
}
});
listMenu.setCellRenderer(new MenuListRenderer());
listMenu.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
scrollPane.setViewportView(listMenu);
emptyButton.setBackground(new java.awt.Color(204, 0, 51));
emptyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
emptyButtonActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(emptyButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 41, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(progressBar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))
.add(scrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 266, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createSequentialGroup()
.add(leftButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(upButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(downButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(rightButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(21, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.add(onOff_Button, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(upButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(leftButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(rightButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(downButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(scrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 133, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(onOff_Button)
.add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(layout.createSequentialGroup()
.add(4, 4, 4)
.add(emptyButton)))
.add(10, 10, 10))
);
pack();
}// </editor-fold>
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
int index = listMenu.getSelectedIndex();
if(startTimeHour.bool){
if(cleanSettings.bool){
startTime = secondLastIndex - 1;
startMinute = (startMinute-1) * 10;
mode = listMenu.getSelectedValue();
if(startTime < 10 && startMinute != 0){
showEntry = new RobotDisplayModel("Reinigungszeit anzeigen", "Startzeit: 0"+startTime+":"+startMinute+"h " +mode);
deleteEntry = new RobotDisplayModel("Reinigungszeit anzeigen", "Startzeit: 0"+startTime+":"+startMinute+"h " +mode);
}
if(startTime > 9 && startMinute == 0){
showEntry = new RobotDisplayModel("Reinigungszeit anzeigen", "Startzeit: "+startTime+":0"+startMinute+"h " +mode);
deleteEntry = new RobotDisplayModel("Reinigungszeit anzeigen", "Startzeit: "+startTime+":0"+startMinute+"h " +mode);
}
if(startTime < 10 && startMinute == 0){
showEntry = new RobotDisplayModel("Reinigungszeit löschen", "Startzeit: 0"+startTime+":0"+startMinute+"h " +mode);
deleteEntry = new RobotDisplayModel("Reinigungszeit löschen", "Startzeit: 0"+startTime+":0"+startMinute+"h " +mode);
}
if(startTime > 9 && startMinute != 0){
showEntry = new RobotDisplayModel("Reinigungszeit löschen", "Startzeit: "+startTime+":"+startMinute+"h " +mode);
deleteEntry = new RobotDisplayModel("Reinigungszeit löschen", "Startzeit: "+startTime+":"+startMinute+"h " +mode);
}
listMenu.setModel(mainMenu);
listMenu.setSelectedIndex(1);
startTimeMinute.bool = false;
startTimeHour.bool = false;
mainMenu.bool = false;
cleanSettings.bool = false;
}
if(startTimeMinute.bool){
listMenu.setModel(cleanSettings);
listMenu.setSelectedIndex(1);
cleanSettings.bool = true;
startMinute = index;
thirdLastIndex = index;
}
if(startTimeHour.bool && !startTimeMinute.bool){
listMenu.setModel(startTimeMinute);
listMenu.setSelectedIndex(1);
secondLastIndex = index;
startTimeMinute.bool = true;
System.out.println(startTimeMinute);
}
}
if(deleteEntry.bool){
startTime = 0;
startMinute = 0;
deleteEntry.bool = false;
startTimeMinute.bool = false;
cleanSettings.bool = false;
mainMenu.bool = false;
listMenu.setModel(mainMenu);
listMenu.setSelectedIndex(1);
showEntry = new RobotDisplayModel("Reinigungszeit anzeigen", "Keine Reinigungszeit vorhanden");
deleteEntry = new RobotDisplayModel("Reinigungszeiten löschen", "Keine Reinigungszeit vorhanden");
}
if(quickStart.bool){
count = count + index*10;
MyTimerTask counter = new MyTimerTask();
for(int j = 0; j<index * 10; j++){
listMenu.setModel(mainMenu);
listMenu.setSelectedIndex(1);
quickStart.bool = false;
mainMenu.bool = false;
MyTimerTask.timer();
i++;
progressBar.setStringPainted(true);
progressBar.setValue(i);
progressBar.paint(progressBar.getGraphics());
if(i>99)
break;
}
listMenu.setModel(mainMenu);
listMenu.setSelectedIndex(1);
quickStart.bool = false;
mainMenu.bool = false;
}
}
private void onOff_ButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(k==1){
listMenu.setModel(offModel);
upButton.setEnabled(false);
downButton.setEnabled(false);
leftButton.setEnabled(false);
rightButton.setEnabled(false);
okButton.setEnabled(false);
k=0;
}else{
listMenu.setEnabled(true);
listMenu.setModel(mainMenu);
listMenu.setSelectedIndex(1);
upButton.setEnabled(true);
downButton.setEnabled(true);
leftButton.setEnabled(true);
rightButton.setEnabled(true);
okButton.setEnabled(true);
startTime = 0;
startMinute = 0;
deleteEntry.bool = false;
startTimeMinute.bool = false;
mainMenu.bool = false;
k=1;
}
}
private void upButtonActionPerformed(java.awt.event.ActionEvent evt) {
int index = listMenu.getSelectedIndex();
int size = listMenu.getModel().getSize();
if(index != 1){
listMenu.setSelectedIndex(index-1);
listMenu.ensureIndexIsVisible(index-1);
}
if(index == 1){
listMenu.setSelectedIndex(size-1);
listMenu.ensureIndexIsVisible(size-1);
}
}
private void leftButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(mainMenu.bool){
if(!startTimeMinute.bool){
listMenu.setModel(mainMenu);
listMenu.setSelectedIndex(lastIndex);
startTimeHour.bool = false;
mainMenu.bool = false;
}
if(startTimeMinute.bool && !cleanSettings.bool){
listMenu.setModel(startTimeHour);
listMenu.setSelectedIndex(secondLastIndex);
startTimeMinute.bool = false;
}
if(cleanSettings.bool){
listMenu.setModel(startTimeMinute);
listMenu.setSelectedIndex(thirdLastIndex);
cleanSettings.bool = false;
}
if(showEntry.bool){
listMenu.setModel(mainMenu);
listMenu.setSelectedIndex(lastIndex);
showEntry.bool = false;
mainMenu.bool = false;
}
}
}
private void rightButtonActionPerformed(java.awt.event.ActionEvent evt) {
Facade facade = new Facade();
int index = listMenu.getSelectedIndex();
if(!mainMenu.bool){
facade.getSelectedRightButton(index);
lastIndex = index;
}
}
private void downButtonActionPerformed(java.awt.event.ActionEvent evt) {
int index = listMenu.getSelectedIndex();
int size = listMenu.getModel().getSize();
if(index != size-1){
listMenu.setSelectedIndex(index+1);
listMenu.ensureIndexIsVisible(index+1);
}
if(index == size-1){
listMenu.setSelectedIndex(1);
listMenu.ensureIndexIsVisible(1);
}
}
private void formComponentResized(java.awt.event.ComponentEvent evt) {
// TODO add your handling code here:
}
private void emptyButtonActionPerformed(java.awt.event.ActionEvent evt) {
progressBar.setValue(0);
System.out.println(mainMenu.getElementAt(2));
i = 0;
}
/**
* @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 [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url]
*/
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(OperatingPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(OperatingPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(OperatingPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(OperatingPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new OperatingPanel().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton downButton;
public javax.swing.JButton emptyButton;
private javax.swing.JButton leftButton;
public javax.swing.JList listMenu;
private javax.swing.JButton okButton;
private javax.swing.JToggleButton onOff_Button;
public javax.swing.JProgressBar progressBar;
private javax.swing.JButton rightButton;
private javax.swing.JScrollPane scrollPane;
private javax.swing.JButton upButton;
// End of variables declaration
}