+++ /dev/null
-package com.axyus.swing.components.wizard;\r
-\r
-import com.axyus.signature.pes.verifier.UnExpectedException;\r
-import com.axyus.swing.components.wizard.WizardProcess.Step;\r
-import com.axyus.swing.components.wizard.WizardProcess.Step.StepValidationException;\r
-import java.awt.Frame;\r
-import java.awt.Image;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.KeyEvent;\r
-import java.util.concurrent.CancellationException;\r
-import java.util.concurrent.ExecutionException;\r
-import javax.swing.AbstractAction;\r
-import javax.swing.Action;\r
-import javax.swing.GroupLayout;\r
-import javax.swing.JComponent;\r
-import javax.swing.JRootPane;\r
-import javax.swing.KeyStroke;\r
-import javax.swing.SwingWorker;\r
-\r
-/**\r
- * @author CBO\r
- * @TODO : Vérifier le bon fonctionnement lié au SwingWorker...\r
- */\r
-public class WizardDialog extends javax.swing.JDialog {\r
-\r
- private WizardProcess wizardProcess;\r
- private int stepNumber = 1;\r
- private SwingWorker worker;\r
-\r
- public WizardDialog(WizardProcess wizardProcess, Frame parent, boolean modal) {\r
- super(parent, modal);\r
- this.wizardProcess = wizardProcess;\r
- initComponents();\r
- progressBar.setVisible(false);\r
- updateEtapeInfo();\r
- setPannelContent();\r
- updateButtonSate();\r
- }\r
-\r
- public void setLogo(Image image) {\r
- this.imagePanel.setImage(image);\r
- }\r
-\r
- public void stepChange() {\r
- updateEtapeInfo();\r
- updateButtonSate();\r
- setPannelContent();\r
- }\r
-\r
- private void updateButtonSate() {\r
- previousButton.setEnabled(getWizardProcess().hasPreviousStep());\r
- nextButton.setEnabled(getWizardProcess().hasNextStep());\r
- cancelButton.setText(getWizardProcess().hasNextStep() ? "Annuler" : "Fermer");\r
- }\r
-\r
- private void setPannelContent() {\r
- getWizardProcess().getCurrentStep().beforeDisplay();\r
- contentPanel.removeAll();\r
- GroupLayout layout = new GroupLayout(contentPanel);\r
- contentPanel.setLayout(layout);\r
- layout.setHorizontalGroup(\r
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(getWizardProcess().getCurrentStep().getUI(), javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));\r
- layout.setVerticalGroup(\r
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(getWizardProcess().getCurrentStep().getUI(), javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));\r
- }\r
-\r
- private void updateEtapeInfo() {\r
- StringBuilder sb = new StringBuilder();\r
- sb.append("<html>");\r
- if (getWizardProcess().getPredictedSteps() != null) {\r
- if (!wizardProcess.getPredictedSteps().isEmpty()) {\r
- int workingStepNumber = 1;\r
- for (Step step : getWizardProcess().getPredictedSteps()) {\r
- if (step.equals(getWizardProcess().getCurrentStep())) {\r
- sb.append("<p><b>").append(workingStepNumber).append(". ").append(step.getTile()).append("<b></p>");\r
- } else {\r
- sb.append("<p>").append(workingStepNumber).append(". ").append(step.getTile()).append("</p>");\r
- }\r
- workingStepNumber++;\r
- }\r
- }\r
- if (!wizardProcess.isStepsPredictionCompleted()) {\r
- sb.append("<p>...</p>");\r
- }\r
- }\r
- sb.append("</html>");\r
- etapesInfo.setText(sb.toString());\r
- if (getWizardProcess().isStepsPredictionCompleted()) {\r
- etapeTitle.setText(getWizardProcess().getCurrentStep().getTile() + " (" + stepNumber + " sur " + getWizardProcess().getPredictedSteps().size() + ")");\r
- } else {\r
- etapeTitle.setText(getWizardProcess().getCurrentStep().getTile());\r
- }\r
- }\r
-\r
- public void startLongStepValidation() {\r
- nextButton.setEnabled(false);\r
- getProgressBar().setVisible(true);\r
- }\r
-\r
- public void stopLongStepValidation() {\r
- getProgressBar().setVisible(false);\r
- \r
- }\r
-\r
- /** This method is called from within the constructor to\r
- * initialize the form.\r
- * WARNING: Do NOT modify this code. The content of this method is\r
- * always regenerated by the Form Editor.\r
- */\r
- @SuppressWarnings("unchecked")\r
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents\r
- private void initComponents() {\r
-\r
- bottomPanel = new javax.swing.JPanel();\r
- cancelButton = new javax.swing.JButton();\r
- nextButton = new javax.swing.JButton();\r
- previousButton = new javax.swing.JButton();\r
- imagePanel = new com.axyus.swing.components.wizard.WizardImagePanel();\r
- etapesTitle = new javax.swing.JLabel();\r
- etapesInfo = new javax.swing.JLabel();\r
- progressBar = new javax.swing.JProgressBar();\r
- etapeTitle = new javax.swing.JLabel();\r
- informationLabel = new javax.swing.JLabel();\r
- contentPanel = new javax.swing.JPanel();\r
-\r
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);\r
- setName("wizardDialog"); // NOI18N\r
-\r
- bottomPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 0, 0, new java.awt.Color(0, 0, 0)));\r
-\r
- cancelButton.setText("Annuler");\r
- cancelButton.addActionListener(new java.awt.event.ActionListener() {\r
- public void actionPerformed(java.awt.event.ActionEvent evt) {\r
- cancelButtonActionPerformed(evt);\r
- }\r
- });\r
-\r
- nextButton.setText("Suivant >");\r
- nextButton.addActionListener(new java.awt.event.ActionListener() {\r
- public void actionPerformed(java.awt.event.ActionEvent evt) {\r
- nextButtonActionPerformed(evt);\r
- }\r
- });\r
-\r
- previousButton.setText("< Précédent");\r
- previousButton.addActionListener(new java.awt.event.ActionListener() {\r
- public void actionPerformed(java.awt.event.ActionEvent evt) {\r
- previousButtonActionPerformed(evt);\r
- }\r
- });\r
-\r
- javax.swing.GroupLayout bottomPanelLayout = new javax.swing.GroupLayout(bottomPanel);\r
- bottomPanel.setLayout(bottomPanelLayout);\r
- bottomPanelLayout.setHorizontalGroup(\r
- bottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)\r
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, bottomPanelLayout.createSequentialGroup()\r
- .addContainerGap(582, Short.MAX_VALUE)\r
- .addComponent(previousButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)\r
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)\r
- .addComponent(nextButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)\r
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)\r
- .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)\r
- .addContainerGap())\r
- );\r
- bottomPanelLayout.setVerticalGroup(\r
- bottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)\r
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, bottomPanelLayout.createSequentialGroup()\r
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)\r
- .addGroup(bottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)\r
- .addComponent(cancelButton)\r
- .addComponent(nextButton)\r
- .addComponent(previousButton))\r
- .addContainerGap())\r
- );\r
-\r
- imagePanel.setBackground(java.awt.Color.white);\r
-\r
- etapesTitle.setFont(new java.awt.Font("Tahoma", 1, 11));\r
- etapesTitle.setText("Etapes");\r
- etapesTitle.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(0, 0, 0)));\r
-\r
- etapesInfo.setText("Informations sur l'avancement");\r
- etapesInfo.setVerticalAlignment(javax.swing.SwingConstants.TOP);\r
-\r
- progressBar.setIndeterminate(true);\r
- progressBar.setString("Veuillez patienter");\r
-\r
- javax.swing.GroupLayout imagePanelLayout = new javax.swing.GroupLayout(imagePanel);\r
- imagePanel.setLayout(imagePanelLayout);\r
- imagePanelLayout.setHorizontalGroup(\r
- imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)\r
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, imagePanelLayout.createSequentialGroup()\r
- .addContainerGap()\r
- .addGroup(imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)\r
- .addComponent(etapesInfo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)\r
- .addComponent(etapesTitle, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)\r
- .addComponent(progressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE))\r
- .addContainerGap())\r
- );\r
- imagePanelLayout.setVerticalGroup(\r
- imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)\r
- .addGroup(imagePanelLayout.createSequentialGroup()\r
- .addContainerGap()\r
- .addComponent(etapesTitle)\r
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)\r
- .addComponent(etapesInfo, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)\r
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)\r
- .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)\r
- .addContainerGap())\r
- );\r
-\r
- etapeTitle.setFont(new java.awt.Font("Tahoma", 1, 11));\r
- etapeTitle.setText("Titre étape");\r
- etapeTitle.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(0, 0, 0)));\r
-\r
- informationLabel.setPreferredSize(new java.awt.Dimension(81, 15));\r
-\r
- contentPanel.setLayout(null);\r
-\r
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());\r
- getContentPane().setLayout(layout);\r
- layout.setHorizontalGroup(\r
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)\r
- .addComponent(bottomPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)\r
- .addGroup(layout.createSequentialGroup()\r
- .addComponent(imagePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)\r
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)\r
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)\r
- .addComponent(contentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 671, Short.MAX_VALUE)\r
- .addComponent(informationLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 671, Short.MAX_VALUE)\r
- .addComponent(etapeTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 671, Short.MAX_VALUE))\r
- .addContainerGap())\r
- );\r
- layout.setVerticalGroup(\r
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)\r
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()\r
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)\r
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()\r
- .addGap(11, 11, 11)\r
- .addComponent(etapeTitle)\r
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)\r
- .addComponent(contentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)\r
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)\r
- .addComponent(informationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)\r
- .addGap(6, 6, 6))\r
- .addComponent(imagePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))\r
- .addGap(0, 0, 0)\r
- .addComponent(bottomPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))\r
- );\r
-\r
- pack();\r
- }// </editor-fold>//GEN-END:initComponents\r
-\r
- private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed\r
- startLongStepValidation();\r
- worker = new SwingWorker<Boolean, String>() {\r
-\r
- @Override\r
- protected Boolean doInBackground() throws Exception {\r
- getWizardProcess().getCurrentStep().validate();\r
- return true;\r
- }\r
-\r
- @Override\r
- protected void done() {\r
- try {\r
- get();\r
- getInformationLabel().setText("");\r
- getWizardProcess().nextStep();\r
- stepNumber++;\r
- stepChange();\r
- } catch (ExecutionException ee) {\r
- if (ee.getCause() instanceof StepValidationException ) {\r
- Exception sve = (Exception) ee.getCause();\r
- getInformationLabel().setText("<html><span style=\"color: red\"><b>" + sve.getLocalizedMessage() + "</b></span></html>");\r
- } else {\r
- throw new UnExpectedException(ee);\r
- }\r
- } catch (InterruptedException ie) {\r
- throw new UnExpectedException(ie);\r
- } catch (CancellationException ce) {\r
- getInformationLabel().setText("<html>Le traitement à été interrompu</html>"); //@TODO : better message here !\r
- } finally {\r
- updateButtonSate();\r
- stopLongStepValidation();\r
- }\r
- }\r
- };\r
- worker.execute();\r
- }//GEN-LAST:event_nextButtonActionPerformed\r
-\r
- private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed\r
- getWizardProcess().cancel();\r
- dispose();\r
- }//GEN-LAST:event_cancelButtonActionPerformed\r
-\r
- private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previousButtonActionPerformed\r
- if (worker != null) {\r
- if (worker.cancel(true)) {\r
- getInformationLabel().setText("<html>Le traitement à été interrompu</html>"); //@TODO : better message here !\r
- }\r
- }\r
- getWizardProcess().previousStep();\r
- stepNumber--;\r
- stepChange();\r
- }//GEN-LAST:event_previousButtonActionPerformed\r
- // Variables declaration - do not modify//GEN-BEGIN:variables\r
- private javax.swing.JPanel bottomPanel;\r
- private javax.swing.JButton cancelButton;\r
- private javax.swing.JPanel contentPanel;\r
- private javax.swing.JLabel etapeTitle;\r
- private javax.swing.JLabel etapesInfo;\r
- private javax.swing.JLabel etapesTitle;\r
- private com.axyus.swing.components.wizard.WizardImagePanel imagePanel;\r
- private javax.swing.JLabel informationLabel;\r
- private javax.swing.JButton nextButton;\r
- private javax.swing.JButton previousButton;\r
- private javax.swing.JProgressBar progressBar;\r
- // End of variables declaration//GEN-END:variables\r
-\r
- public void forceNextStep(java.awt.event.ActionEvent evt){\r
- nextButtonActionPerformed(evt);\r
- }\r
- /**\r
- * @return the wizardProcess\r
- */\r
- public WizardProcess getWizardProcess() {\r
- return wizardProcess;\r
- }\r
-\r
- /**\r
- * @param wizardProcess the wizardProcess to set\r
- */\r
- public void setWizardProcess(WizardProcess wizardProcess) {\r
- this.wizardProcess = wizardProcess;\r
- }\r
-\r
- /**\r
- * @return the informationLabel\r
- */\r
- public javax.swing.JLabel getInformationLabel() {\r
- return informationLabel;\r
- }\r
-\r
- /**\r
- * @param informationLabel the informationLabel to set\r
- */\r
- public void setInformationLabel(javax.swing.JLabel informationLabel) {\r
- this.informationLabel = informationLabel;\r
- }\r
-\r
- /**\r
- * @return the progressBar\r
- */\r
- public javax.swing.JProgressBar getProgressBar() {\r
- return progressBar;\r
- }\r
-\r
- public String getNextButtonText(){\r
- return nextButton.getText();\r
- }\r
- public void setNextButtonText(String txt){\r
- nextButton.setText(txt);\r
- }\r
- @Override\r
- protected JRootPane createRootPane() {\r
- KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0);\r
- JRootPane rp = new JRootPane();\r
- Action escapeAction = new AbstractAction("Annuler") {\r
- @Override\r
- public void actionPerformed(ActionEvent evt) {\r
- cancelButton.doClick();\r
- }\r
- };\r
- rp.registerKeyboardAction(escapeAction,"TOTOTOTO",ks,JComponent.WHEN_IN_FOCUSED_WINDOW);\r
- return rp;\r
- }\r
- \r
-}\r