Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 Michael Ruflin, Andr´┐Ż Locher, Claudia von Bastian. This file is part of Tatool. Tatool is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Tatool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tatool. If not, see <http://www.gnu.org/licenses/>. /
 
 package ch.tatool.app.gui;
 
 import java.awt.Font;
 import java.awt.Image;
 import java.util.Date;
 import java.util.Map;
 
 
 
Displays module information to the user. This frame is the main window the user interacts and therefore hosts the overall application menu.

Author(s):
Michael Ruflin
 
 public class ModuleOverviewFrame extends javax.swing.JFrame implements
 
 	private static final long serialVersionUID = 8223517200199952504L;
 
 	Logger logger = LoggerFactory.getLogger(ModuleOverviewFrame.class);

Module service.
 
Module data service.
 
 	private DataService dataService;

Property Export service.
 
Module execution service.
 
GuiController.
 
Module statistics provider.
 
Module this frame displays.
	private Module module;

Executor object during execution.
	private Executor executor;
	private Messages messages;
		.info("Create new instance of ModuleOverviewFrame"); //$NON-NLS-1$
	}

Called by Spring after all beans have been set.
	public void init() {
	}

Set the module displayed by the frame.

Parameters:
module
	public void initialize(Module module) {
		this. = module;
		// initialize the statistics
		// updates the UI with information provided by the module
		java.net.URL iconUrl = this.getClass().getResource("/ch/tatool/app/gui/icon.png"); //$NON-NLS-1$
		Image icon = getToolkit().getImage(iconUrl); 
	}
	private void initializeModuleInfoProvider() {
		// check whether a provider class is defined in the module
		String providerClass = 
		if (providerClass != null) {
			// create an instance - fail if an error occured
			ModuleInfoProvider infoProvider = (ModuleInfoProvider) AppUtils
					.createInstance(providerClass,
							ModuleInfoProvider.classtrue);
			 = infoProvider;
else {
		}
		// Add module info panel if we got a provider
		if ( != null) {
else {
		}
	}

Updates the displayed data with the latest information from the module.
	private void updateUI() {
		// update the ui
		// module name
		String moduleName = .getString("ModuleOverviewFrame.label.unknownModule"); //$NON-NLS-1$
			moduleName = props.get(.);
		}
		// window title
		setTitle(.getString("General.title") + " - " + moduleName); //$NON-NLS-1$
		// check the module exporters
		// update the module info
		if ( != null) {
		}
	}
	private void initModuleExporters() {
		if (.size() > 0) {
			while(it.hasNext()) { 
				final String exporterKey = it.next(); 
				DataExporter ex = .get(exporterKey);
				// get last export date while we're scanning through
				if (.getLastExportDate(exporterKey) == null) {
else if ( == null) {
				}
				JButton exportButton = new JButton();
				exportButton.setFont(new Font("Tahoma", 0, 13)); //$NON-NLS-1$
				exportButton.setText(ex.getExporterName());
				exportButton.setMaximumSize(new Dimension(109, 25));
				exportButton.setMinimumSize(new Dimension(109, 25));
				exportButton.setPreferredSize(new Dimension(109, 25));
		        exportButton.addActionListener(new ActionListener() {
		            public void actionPerformed(ActionEvent evt) {
		            	exportData(exporterKey);
		            }
		        });
				.add(exportButton);
		}
	}

Enables or disables the module management links.
	public void setModuleManagementEnabled(boolean enabled) {
		//manageTrainingsMenuItem.setVisible(enabled);
	}
	// TrainingExecutionListener
	public void processExecutionPhase(ExecutionContext context) {
		switch (context.getPhase()) {
			break;
		}
	}
	private void moduleFinished() {
		// update the ui
		if (this. != null) {
			if ( != null) {
				while(it.hasNext()) { 
					final String exporterKey = it.next(); 
					DataExporter ex = .get(exporterKey);
					if (ex.isAutoExport()) {
						exportData(exporterKey);
					}
				}
			}
		}
	}
	private void startModule() {
		if (moduleScheduler != null) {
			moduleScheduler.setMessages();
			message = moduleScheduler.isSessionStartAllowed();
			if (message.isSessionStartAllowed()) {
else {
				JOptionPane.showMessageDialog(this,
					    message.getMessageText(),
			}
else {
			// if we don't have a scheduler, allow the start of the module
		}
	}
	private void exportData(final String exporterKey) {
		// check whether there is something to export
			// check whether the user really wants to upload
			int result = JOptionPane
							this,
							.getString("ModuleOverviewFrame.label.confirmExport"), //$NON-NLS-1$
							.getString("ModuleOverviewFrame.export.windowTitle"), .); //$NON-NLS-1$
			if (result != .) {
				return;
else {
				//re-upload everything starting from -1
				.getModuleProperties().put(exporterKey + "." + ."-1"); //$NON-NLS-1$
			}
		}
		// perform the export in a new thread
		final ProgressDialog progressDialog = new ProgressDialog(thistrue);
		progressDialog.setTitle(.getString("General.progress.label.pleaseWait")); //$NON-NLS-1$
		progressDialog.setLabel(.getString("ModuleOverviewFrame.export.label.exportingData")); //$NON-NLS-1$
		// call setVisible() from another thread, as this thread would get blocked otherwise
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				progressDialog.setVisible(true);
			}
		});
		// Do the work in a separate thread
		new Thread() {
			public void run() {
				doExport(progressDialogexporterKey);
			}
		}.start();
	}
	// Non-EDT thread
	private void doExport(final ProgressDialog progressDialogString exporterKey) {
		final String errorMessage = .exportData(thisexporterKey);
		final Date exportDate = .getLastExportDate(exporterKey);
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				exportFinished(progressDialogerrorMessageexportDate);
			}
		});
	}
	private void exportFinished(ProgressDialog progressDialogString errorMessageDate exportDate) {
		progressDialog.dispose();
		if (errorMessage != null) {
			JOptionPane.showMessageDialog(thiserrorMessage.getString("General.errorMessage.windowTitle.error"), .); //$NON-NLS-1$
		}
		// update the save date
		if (exportDate != null) {
			// update the module info
			if ( != null) {
			}
		}
		if (errorMessage == null) {
			JOptionPane.showMessageDialog(this.getString("ModuleOverviewFrame.export.label.exportSuccessful"), .getString("ModuleOverviewFrame.export.windowTitle"), .); //$NON-NLS-1$ //$NON-NLS-2$
		}
	}
	// Getters and Setters
	}
	public void setModuleService(ModuleService moduleService) {
		this. = moduleService;
	}
	}
	public void setExecutionService(
			ExecutionService executionService) {
		this. = executionService;
	}
		return ;
	}
	public void setDataService(DataService dataService) {
		this. = dataService;
	}
	}
	public void setGuiController(GuiController guiController) {
		this. = guiController;
	}
	}
	public void setDataExportService(DataExportService dataExportService) {
		this. = dataExportService;
	}
	public void setMessages(Messages messages) {
    	this. = messages;
    }
    
    public Messages getMessages() {
		return ;
	}
	// UI Action methods
	private void manageTrainingsMenuItemActionPerformed(ActionEvent evt) {// GEN-FIRST:event_manageTrainingsMenuItemActionPerformed
	}// GEN-LAST:event_manageTrainingsMenuItemActionPerformed
	private void exitMenuItemActionPerformed(ActionEvent evt) {// GEN-FIRST:event_exitMenuItemActionPerformed
	}// GEN-LAST:event_exitMenuItemActionPerformed
	private void aboutMenuItemActionPerformed(ActionEvent evt) {// GEN-FIRST:event_aboutMenuItemActionPerformed
		JDialog aboutDialog = new AboutDialog(thisfalse);
		aboutDialog.setLocationRelativeTo(null);
		aboutDialog.setVisible(true);
	}// GEN-LAST:event_aboutMenuItemActionPerformed
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"
	// <editor-fold defaultstate="collapsed"
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        JPanel jPanel5 = new JPanel();
        JPanel jPanel1 = new JPanel();
        JPanel jPanel2 = new JPanel();
         = new JPanel();
        JPanel jPanel4 = new JPanel();
        JButton exitButton = new JButton();
         = new JButton();
        JLabel jLabel1 = new JLabel();
         = new JPanel();
        JMenuBar jMenuBar1 = new JMenuBar();
        JMenu jMenu1 = new JMenu();
         = new JMenuItem();
        JSeparator jSeparator1 = new JSeparator();
        JMenuItem exitMenuItem = new JMenuItem();
        JMenu jMenu3 = new JMenu();
        JMenuItem helpMenuItem = new JMenuItem();
        JMenuItem aboutMenuItem = new JMenuItem();
        GroupLayout jPanel5Layout = new GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(.)
            .addGap(0, 100, .)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(.)
            .addGap(0, 100, .)
        );
        setTitle(.getString("General.title")); //$NON-NLS-1$
        setMinimumSize(new Dimension(600, 350));
        jPanel1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        jPanel2.setPreferredSize(new Dimension(400, 400));
        .setBorder(BorderFactory.createTitledBorder("")); //$NON-NLS-1$
        .setMinimumSize(new Dimension(633, 402));
        .setPreferredSize(new Dimension(400, 400));
        GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(.)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(.)
        );
        exitButton.setFont(new Font("Tahoma", 0, 13)); //$NON-NLS-1$
        exitButton.setText(.getString("ModuleOverviewFrame.label.exit")); //$NON-NLS-1$
        exitButton.setMaximumSize(new Dimension(109, 25));
        exitButton.setMinimumSize(new Dimension(109, 25));
        exitButton.setPreferredSize(new Dimension(109, 25));
        exitButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });
        .setFont(new Font("Tahoma", 0, 13)); //$NON-NLS-1$
        .setText(.getString("ModuleOverviewFrame.label.start")); //$NON-NLS-1$
        .setMaximumSize(new Dimension(109, 25));
        .setMinimumSize(new Dimension(109, 25));
        .setPreferredSize(new Dimension(109, 25));
            public void actionPerformed(ActionEvent evt) {
                startModuleButtonActionPerformed(evt);
            }
        });
        jLabel1.setIcon(new ImageIcon(getClass().getResource("/ch/tatool/app/gui/tatool.png"))); // NOI18N //$NON-NLS-1$
        .setLayout(new GridLayout(0, 1, 0, 5));
        GroupLayout jPanel4Layout = new GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(.)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(.)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel1., 110, .)
                        .addGap(9, 9, 9))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(10, 10, 10))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(exitButton...)
                        .addContainerGap())
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap(..))))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(.)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(30, 30, 30)
                .addPreferredGap(.)
                .addPreferredGap(.)
                .addContainerGap(..))
        );
        GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(.)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel2., 418, .))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(.)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(178, .))
            .addComponent(jPanel2., 314, .)
        );
        getContentPane().add(jPanel1.);
        jMenu1.setText(.getString("ModuleOverviewFrame.labelMenu.file")); //$NON-NLS-1$
        .setText(.getString("ModuleOverviewFrame.labelMenu.myModules")); //$NON-NLS-1$
            public void actionPerformed(ActionEvent evt) {
                manageTrainingsMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add();
        jMenu1.add(jSeparator1);
        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(..));
        exitMenuItem.setText(.getString("ModuleOverviewFrame.labelMenu.exit")); //$NON-NLS-1$
        exitMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(exitMenuItem);
        jMenuBar1.add(jMenu1);
        jMenu3.setText(.getString("ModuleOverviewFrame.labelMenu.help")); //$NON-NLS-1$
        helpMenuItem.setAccelerator(KeyStroke.getKeyStroke(., 0));
        helpMenuItem.setText(.getString("ModuleOverviewFrame.labelMenu.helpTopics")); //$NON-NLS-1$
        helpMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                helpMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(helpMenuItem);
        aboutMenuItem.setText(.getString("ModuleOverviewFrame.labelMenu.aboutTatool")); //$NON-NLS-1$
        aboutMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        jMenu3.add(aboutMenuItem);
        jMenuBar1.add(jMenu3);
        setJMenuBar(jMenuBar1);
        pack();
    }// </editor-fold>//GEN-END:initComponents
	private void startModuleButtonActionPerformed(ActionEvent evt) {// GEN-FIRST:event_startTrainingButtonActionPerformed
	}// GEN-LAST:event_startTrainingButtonActionPerformed
	private void exitButtonActionPerformed(ActionEvent evt) {// GEN-FIRST:event_exitButtonActionPerformed
	}// GEN-LAST:event_exitButtonActionPerformed
	private void helpMenuItemActionPerformed(ActionEvent evt) {// GEN-FIRST:event_aboutMenuItem1ActionPerformed
        if( !java.awt.Desktop.isDesktopSupported() ) {
            ..println.getString("ModuleOverviewFrame.errorMessage.desktopError") ); //$NON-NLS-1$
            System.exit( 1 );
        }
        java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
        if( !desktop.isSupported.... ) ) {
            JOptionPane.showMessageDialog(this.getString("ModuleOverviewFrame.errorMessage.desktopError2")); //$NON-NLS-1$
        } else {
            try {
            java.net.URI uri = new java.net.URI"http://www.tatool.ch/faq.htm" ); //$NON-NLS-1$
            desktop.browseuri );
        } catch ( Exception e ) {
            ..printlne.getMessage() );
        }
        }
	}// GEN-LAST:event_aboutMenuItem1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables