RJMFrameDialog Usage

Submitted by code_admin on Wed, 07/25/2018 - 10:31

Usage

  1. String sourcePath = "";
  2. LocalArchiveEdit dlg = new LocalArchiveEdit();
  3.  
  4. dlg.setTitle("Create a new Local Archive");
  5. dlg.doModal(p_Parent);
  6. String returned = (String) dlg.getReturnValue();
  7. if (null==returned) return null;
  8.  
  9. name = dlg.getInpName();
  10. description = dlg.getInpDescription();
  11. sourcePath = dlg.getInpPath();

Derived Class

  1. package metcarob.com.mediaorganiser.mainapp.ui;
  2.  
  3. import java.awt.event.KeyEvent;
  4.  
  5. import java.io.File;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10.  
  11. import java.util.Map;
  12.  
  13. import javax.swing.JFileChooser;
  14. import javax.swing.JOptionPane;
  15. import javax.swing.KeyStroke;
  16.  
  17. import javax.swing.filechooser.FileFilter;
  18.  
  19. import metcarob.com.common.ui.RJMFrameDialog.FieldTypes.RJMFrameDialogFieldBrowsePath;
  20. import metcarob.com.common.ui.RJMFrameDialog.FieldTypes.RJMFrameDialogFieldLabel;
  21. import metcarob.com.common.ui.RJMFrameDialog.FieldTypes.RJMFrameDialogFieldText;
  22. import metcarob.com.common.ui.RJMFrameDialog.PossibleReturnValue;
  23. import metcarob.com.common.ui.RJMFrameDialog.RJMFrameDialog;
  24. import metcarob.com.common.ui.RJMFrameDialog.RJMFrameDialogField;
  25.  
  26. public class RelationshipEditDLG extends RJMFrameDialog {
  27.     public RelationshipEditDLG() throws Exception {
  28.         super();
  29.         List<PossibleReturnValue> retVals = new ArrayList<PossibleReturnValue>();
  30.         retVals.add(new PossibleReturnValue("OK","OK",KeyStroke.getKeyStroke("ENTER"),true));
  31.         retVals.add(new PossibleReturnValue(null,"Cancel",KeyStroke.getKeyStroke("ESCAPE"),true));
  32.        
  33.         RJMFrameDialogField field = null;
  34.         this.AddField(new RJMFrameDialogFieldLabel("Relationship"));
  35.         field = new RJMFrameDialogFieldText("Name:","");
  36.         field.setEnabled(false);
  37.         this.AddField("NAME",field);
  38.         field = new RJMFrameDialogFieldText("Description:","");
  39.         field.setEnabled(false);
  40.         this.AddField("DESC",field);
  41.         field = new RJMFrameDialogFieldBrowsePath("File:","","...",JFileChooser.FILES_ONLY,new FileFilter() {
  42.                                         public boolean accept(File f) {
  43.                                           return f.getName().toLowerCase().endsWith(".db")
  44.                                               || f.isDirectory();
  45.                                         }
  46.                                    
  47.                                         public String getDescription() {
  48.                                           return "DB Files";
  49.                                         }
  50.                                       }
  51.         );
  52.         field.setEnabled(false);
  53.         this.AddField("FILE",field);
  54.         field = new RJMFrameDialogFieldBrowsePath("Directory:","","...",JFileChooser.DIRECTORIES_ONLY,null);
  55.         field.setEnabled(false);
  56.         this.AddField("DIR",field);
  57.  
  58.         this.Setup(retVals);
  59.     }
  60.  
  61.      public void setInpName(String p_dat) {this.getField("NAME").setText(p_dat);};
  62.      public void setInpDescription(String p_dat) {this.getField("DESC").setText(p_dat);};
  63.      public void setInpFile(String p_dat) {this.getField("FILE").setText(p_dat);};
  64.      public void setInpDirectory(String p_dat) {this.getField("DIR").setText(p_dat);};
  65.  
  66.     public String getInpName() {return this.getField("NAME").getText();};
  67.     public String getInpDescription() {return this.getField("DESC").getText();};
  68.     public String getInpFile() {return this.getField("FILE").getText();};
  69.     public String getInpDirectory() {return this.getField("DIR").getText();};
  70.  
  71.     public boolean validateReturn(Object p_ReturnValue) {
  72.         if (p_ReturnValue!=null) {
  73.             if (p_ReturnValue.equals("OK")) {
  74.                 if (getInpName().length()<2) {
  75.                     JOptionPane.showMessageDialog(m_Parent, "You must enter a name of more than 3 charecters");                                                        
  76.                     return false;
  77.                 }
  78.             }
  79.         };
  80.         return true;
  81.     }
  82. }

Then add actions as

  1.     private transient Action m_OpenAction = new ModalFormAction(this) {
  2.         {
  3.             putValue(NAME, m_strMenuOpen);
  4.             putValue(LARGE_ICON_KEY, new ImageIcon(RelationshipFrame.class.getResource("openfile.gif")));            
  5.             putValue(SMALL_ICON, getValue(LARGE_ICON_KEY));        
  6.         }
  7.  
  8.         public void actionPreformedDerived2(ActionEvent actionEvent) throws Exception {
  9.             //Write Code
  10.             //No need to if enabled
  11.             //No need for start or end long running operation
  12.             //No need for exception messagebox
  13.         }
  14.     };

Simple wrapper to wrap a JPanel

  1. package metcarob.com.xmlwasher.ui;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import javax.swing.JPanel;
  7. import javax.swing.KeyStroke;
  8.  
  9. import metcarob.com.common.ui.RJMFrameDialog.RJMFrameDialog;
  10. import metcarob.com.common.ui.RJMFrameDialog.PossibleReturnValue;
  11. import metcarob.com.common.ui.RJMFrameDialog.FieldTypes.RJMFrameDialogFieldSubPanel;
  12.  
  13. public class MainWindowDLG extends RJMFrameDialog {
  14.  
  15.     public MainWindowDLG() throws Exception {
  16.         super();
  17.         List<PossibleReturnValue> retVals = new ArrayList<PossibleReturnValue>();
  18.         retVals.add(new PossibleReturnValue(null,null,KeyStroke.getKeyStroke("ESCAPE"),true));
  19.        
  20.        
  21.         JPanel pan = new JPanel();
  22.         RJMFrameDialogFieldSubPanel field = new RJMFrameDialogFieldSubPanel(pan, 10);
  23.         this.AddField("MAIN_PANEL",field);
  24.        
  25.         this.Setup(retVals);   
  26.     };
  27.    
  28. }

Close Dialog from code

Call ReturnActionCall

  1.         this.ReturnActionCall("SETTINGSUPDATE");

Google Juice

RJMDialog

RJM Article Type
Quick Reference