IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SWT/JFace Java Discussion :

incorporé un StructuredTextEditor dans un SWT Dialog


Sujet :

SWT/JFace Java

  1. #1
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut incorporé un StructuredTextEditor dans un SWT Dialog
    Hello,

    Je cherche a placé un StructuredTextEditor dans un Dialog es-ce que c'est possible ? Si oui comment et si non comment placé un text area qui reconnait le formatage XML.

    Merci

  2. #2
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut
    a première vue ca n'as pas l'air possible ... es-ce que StyledText peut m'aider dans ma quête ? Si oui avez vous un petit exemple autre que

    http://www.java2s.com/Code/Java/SWT-...ledTextAPI.htm

    car je ne vois pas trop l'intérêt d'utiliser un modifyText car cela ne prend en compte que le character courrant tapper ...

    d autres pistes ?

  3. #3
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut
    j ai tenté cette approche :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     
        /**
         * Creates the content of the dialog
         * @param shell
         */
        private void createContents(final Shell shell) {
     
        	shell.setLayout(null);
        	final StyledText textarea = new StyledText(shell,SWT.MULTI);
        	// Add the syntax coloring handler
        	textarea.addExtendedModifyListener(new ExtendedModifyListener() {
              public void modifyText(ExtendedModifyEvent event) {
            	  // Determine the ending offset
                int end = event.start + event.length - 1;
             // If they typed something, get it
                if (event.start > 0) {                         
               	String text = textarea.getText();
     
                  // Create a collection to hold the StyleRanges
                  java.util.List ranges = new java.util.ArrayList();
                  int startIndex = 0;
                  int indexOfEndingChar = 0;
                  int endIndex = text.lastIndexOf('>');
                  int tmpIndex = 0;
                  boolean stop = false;
                  while(!stop) {
                	tmpIndex =+ startIndex + indexOfEndingChar;
                	startIndex =+ text.indexOf("<",tmpIndex);
                	int length = 0;
                	if (startIndex > -1) {
                		indexOfEndingChar = text.indexOf(">",startIndex);
                		if (indexOfEndingChar > -1) {
                			length = indexOfEndingChar - startIndex;
                			ranges.add(new StyleRange(startIndex, length + 1, green, null, SWT.BOLD));
                		}
     
                	}
                		if (tmpIndex >= endIndex || tmpIndex <= -1) {
                			stop = true;
                		}
                  }
     
                  // If we have any ranges to set, set them
                  if (!ranges.isEmpty()) {
                	  StyleRange [] styleRanges = new StyleRange[ranges.size()];
                	  for (int i = 0; i < ranges.size();i++) {
                		  Object o = ranges.get(i);
                		  StyleRange styleRange = (StyleRange) o;
                		  styleRanges[i] = styleRange;
     
                	  }
                	  textarea.setStyleRanges(styleRanges);
                  }
                }
              }
            });
        	textarea.setText(this.property.getValue());
        	textarea.setBounds(0, 0, 450, 300);
        	final Button okButton = new Button(shell, SWT.NONE);
        	okButton.setBounds(0, 330, 80, 20);
        	okButton.setText("Ok");
        	okButton.setSelection(true);
        	Listener listener = new Listener() {
    		      public void handleEvent(Event event) {
    		    	  if (event.widget == okButton) {
    		    		  text = textarea.getText();
    		    		  dialog.close();
    		    	  }
    		    	}};
    		okButton.addListener(SWT.Selection, listener);
        	final Button cancelButton = new Button(shell, SWT.NONE);
        	cancelButton.setBounds(370, 330, 80, 20);
        	cancelButton.setText("Cancel");
        	Listener listenerCancel = new Listener() {
    		      public void handleEvent(Event event) {
    		    	  if (event.widget == cancelButton) {
    		    		  dialog.close();
    		    	  }
    		    	}};
     
    		cancelButton.addListener(SWT.Selection, listenerCancel);
        }
    et parsé la valeur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <test>valeur</test> 
    <asdf>test</asdf/>
    <true>tes</true>
    mais j obtiens le resultat du screenshot quelqu un aurait il une idée de ce que je fais de faux
    merci

  4. #4
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Points : 2 336
    Points
    2 336
    Par défaut
    résolu

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
                  while(!stop) {
                	tmpIndex =+  indexOfEndingChar;
                	startIndex =+ text.indexOf("<",tmpIndex);
                	int length = 0;
                	if (startIndex > -1) {
     
                		indexOfEndingChar = text.indexOf(">",startIndex);
                		if (indexOfEndingChar > -1) {
                			length = indexOfEndingChar - startIndex;
                			ranges.add(new StyleRange(startIndex, length + 1, green, null, SWT.BOLD));
                		}
     
                	}
                		if (startIndex >= endIndex || startIndex <= -1) {
                			stop = true;
                		}
                  }
     
                  // If we have any ranges to set, set them
                  if (!ranges.isEmpty()) {
                	  StyleRange [] styleRanges = new StyleRange[ranges.size()];
                	  for (int i = 0; i < ranges.size();i++) {
                		  Object o = ranges.get(i);
                		  StyleRange styleRange = (StyleRange) o;
                		  styleRanges[i] = styleRange;
     
                	  }
                	  textarea.setStyleRanges(styleRanges);
                  }
                }
              }
            });

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [VB.NET] incorporer une image dans un exe
    Par joefou dans le forum VB.NET
    Réponses: 6
    Dernier message: 09/12/2005, 11h36
  2. incorporation du sp1 dans windows cd
    Par lefty dans le forum Windows XP
    Réponses: 2
    Dernier message: 21/08/2005, 23h31
  3. [MFC] affichage image caméra dans un projet dialog
    Par Vestaproman dans le forum MFC
    Réponses: 3
    Dernier message: 07/02/2005, 14h27
  4. [FLASH MX] Incorporer un swf dans mon projet
    Par Toutouffe dans le forum Flash
    Réponses: 2
    Dernier message: 19/01/2005, 13h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo