« Copy & paste » : différence entre les versions

De GENIUS
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
 
(8 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
<font color=#556B2F>'''GENIUS'''</font> proposes an evolved "'''Copy & Paste'''" functionnality meaning its possible to store in the clipboard a complete widget rather than the values one by one. Let us see how to do it progressively on the following example ...
<font color=#556B2F>'''GENIUS'''</font> proposes an evolved "'''Copy & Paste'''" functionnality meaning its possible to store in the clipboard a complete widget rather than the values one by one. Let us see how to do it progressively on the following example ...


=== Creation of a widget to be copied ===
== Creation of a widget to be copied ==


First, let us create a widget extending from a [{{PathCurrentJavaDoc}}/fr/cnes/genius/lowLevel/GPanel.html GPanel] implementing the [{{PathCurrentJavaDoc}}/fr/cnes/genius/main/GListener.html GListener] and [{{PathCurrentJavaDoc}}/fr/cnes/genius/main/GReadWrite.html GReadWrite] interfaces (<u>it is mandatory</u>) and owning some data (here two reals, one boolean and a string).
First, let us create a widget extending from a [{{PathCurrentJavaDoc}}/fr/cnes/genius/lowLevel/GPanel.html GPanel] implementing the [{{PathCurrentJavaDoc}}/fr/cnes/genius/main/GListener.html GListener] and [{{PathCurrentJavaDoc}}/fr/cnes/genius/main/GReadWrite.html GReadWrite] interfaces (<u>it is mandatory</u>) and owning some data (here two reals, one boolean and a string).
Ligne 45 : Ligne 45 :
== Preparing the Copy & Paste functionnality ==
== Preparing the Copy & Paste functionnality ==


First, we are going to link the **Copy & Paste** function to the label: a contextual menu will appear after clicking on the right button of the mouse when it will be above this label. To do that, we will use the <font color=#4169E1>attachCopyPasteMenu()</font> method. Two solutions are available:
First, we are going to link the '''Copy & Paste''' function to the label: a contextual menu will appear after clicking on the right button of the mouse when it will be above this label. To do that, we will use the <font color=#4169E1>attachCopyPasteMenu()</font> method. Two solutions are available:
* to do it inside the constructor, meaning it will allways be active
* to do it inside the constructor, meaning it will allways be active
* to redefine the <font color=#4169E1>attachCopyPasteMenu()</font> method for this widget and it will be up to the user of the widget who will decide if the functionnality will be active or not
* to redefine the <font color=#4169E1>attachCopyPasteMenu()</font> method for this widget and it will be up to the user of the widget who will decide if the functionnality will be active or not


On the example, we will choose the seconde option ...
On the example, we will choose the second option ...


<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
Ligne 91 : Ligne 91 :
See on the screen copies the result of such code ...
See on the screen copies the result of such code ...


First display ... [[File:CopyPaste1.jpg]]
First display ...


User updating data ... [[File:CopyPaste2.jpg]]
[[File:CopyPaste1.jpg]]


Copy & Paste these data ... [[File:CopyPaste3.jpg]]
User updating data ...


Reloading the widget ... [[File:CopyPaste1.jpg]]
[[File:CopyPaste2.jpg]]


Paste data ... [[File:CopyPaste4.jpg]]
Copy & Paste these data ...


We restored them ! [[File:CopyPaste2.jpg]]
[[File:CopyPaste3.jpg]]


=== Another way to do it ===
Reloading the widget ...
 
[[File:CopyPaste1.jpg]]
 
Paste data ...
 
[[File:CopyPaste4.jpg]]
 
We restored them !
 
[[File:CopyPaste2.jpg]]
 
== Another way to do it ==


Rather than to use the label (or anything else) to attach the contextual menu, it is also possible to get this menu everywhere on your widget. To do it, you will just have to change these lines in the <font color=#4169E1>attachCopyPasteMenu()</font> and <font color=#4169E1>after()</font> methods:
Rather than to use the label (or anything else) to attach the contextual menu, it is also possible to get this menu everywhere on your widget. To do it, you will just have to change these lines in the <font color=#4169E1>attachCopyPasteMenu()</font> and <font color=#4169E1>after()</font> methods:
Ligne 123 : Ligne 135 :
[[File:CopyPaste5.jpg]]
[[File:CopyPaste5.jpg]]


But as sometimes, you may need to have several different "**Copy & Paste**" in the same [{{PathCurrentJavaDoc}}/fr/cnes/genius/lowLevel/GPanel.html GPanel]] : for example, one for the complete set of data and other ones for each data (or part of the data), it is important to know what you are going to copy or paste !
But as sometimes, you may need to have several different "'''Copy & Paste'''" in the same [{{PathCurrentJavaDoc}}/fr/cnes/genius/lowLevel/GPanel.html GPanel] : for example, one for the complete set of data and other ones for each data (or part of the data), it is important to know what you are going to copy or paste !
And it is precisely the role of the "title" argument : by given a not void character string, it will appear on the contextual menu.
And it is precisely the role of the "title" argument : by given a not void character string, it will appear on the contextual menu.


Ligne 129 : Ligne 141 :
   test.attachCopyPasteMenu("All the data", CopyPasteOperation.Copy, CopyPasteOperation.Paste);
   test.attachCopyPasteMenu("All the data", CopyPasteOperation.Copy, CopyPasteOperation.Paste);
</syntaxhighlight>
</syntaxhighlight>


[[File:CopyPaste51.jpg]]
[[File:CopyPaste51.jpg]]


== More than Copy & Paste ! ==
== More than Copy & Paste ! ==


It is also possible to Import or Export these data into a file. To do it, you will just have to add these operations when calling the <font color=#4169E1>attachCopyPasteMenu()</font>:
It is also possible to Import or Export these data into a file ans since V1.10 to reset the data. To do it, you will just have to add these operations when calling the <font color=#4169E1>attachCopyPasteMenu()</font>:


<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
   test.attachCopyPasteMenu(null, CopyPasteOperation.Copy, CopyPasteOperation.Paste,
   test.attachCopyPasteMenu(null, CopyPasteOperation.Copy, CopyPasteOperation.Paste,
                             CopyPasteOperation.Import, CopyPasteOperation.Export);
                             CopyPasteOperation.Import, CopyPasteOperation.Export, CopyPasteOperation.Reset);
</syntaxhighlight>
</syntaxhighlight>


Ligne 151 : Ligne 161 :


Then a File manager will appear where we will have the possibility to choose our file.
Then a File manager will appear where we will have the possibility to choose our file.




[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]]  
[[WELCOME_TO_THE_GENIUS_WIKI|Return to the introduction ↑]]  
[[Plots|Go to the next page →]]
[[Plots|Go to the next page →]]

Dernière version du 17 décembre 2020 à 17:23

GENIUS proposes an evolved "Copy & Paste" functionnality meaning its possible to store in the clipboard a complete widget rather than the values one by one. Let us see how to do it progressively on the following example ...

Creation of a widget to be copied

First, let us create a widget extending from a GPanel implementing the GListener and GReadWrite interfaces (it is mandatory) and owning some data (here two reals, one boolean and a string).

public class TestForCopyAndPaste extends GPanel implements GListener, GReadWrite {
	
  private GLabel lab;
  private GEntryReal val1;
  private GEntryReal val2;
  private GEntryString vals;
  private GCheckBox cb;
	
  public TestForCopyAndPaste () {
		
    lab = new GLabel("Label ...");
    val1 = new GEntryReal("Val1", 0.);
    val2 = new GEntryReal("Val2", 0.);
    cb = new GCheckBox("Display String");
    vals = new GEntryString("String", "");
		
  }
	
  public void generic() throws GException {
    put(lab);
    put(val1);
    put(val2);
    put(cb);
    if ( cb.isSelected() ) put(vals);
  }
	
  public void display() throws GException { generic(); }

  public void read() throws GException { generic(); }
  public void write() throws GException { generic(); }

  public void before(GEvent arg0) throws GException { }
  public void after(GEvent arg0) throws GException { }

}

Preparing the Copy & Paste functionnality

First, we are going to link the Copy & Paste function to the label: a contextual menu will appear after clicking on the right button of the mouse when it will be above this label. To do that, we will use the attachCopyPasteMenu() method. Two solutions are available:

  • to do it inside the constructor, meaning it will allways be active
  • to redefine the attachCopyPasteMenu() method for this widget and it will be up to the user of the widget who will decide if the functionnality will be active or not

On the example, we will choose the second option ...

  public void attachCopyPasteMenu (String title, CopyPasteOperation... operationList) {
    lab.attachCopyPasteMenu(title, operationList);
  }

Then, we will have to manage this special event in the after() method of our widget : calling the handleCopyPasteEvent() method will execute the action (Copy, Paste, ...).

  public void after(GEvent arg0) throws GException {
		
    boolean cpEvent = handleCopyPasteEvent(lab, arg0);

    if ( !cpEvent ) { System.out.println("Nothing to do with Copy&Paste ..."); }
    else            { System.out.println("Copy&Paste action ..."); }
        
  }

Testing it

Now we are able to call for this widget via an executable method:

  public static void main(String[] args) throws GException {
		
  TestForCopyAndPaste test = new TestForCopyAndPaste();
  // We activate the Copy&Paste functionnality ...
  // For the moment the argument "title" is not used ...
  test.attachCopyPasteMenu(null, CopyPasteOperation.Copy, CopyPasteOperation.Paste);

  GFrame frame = new GFrame("TestForCopyAndPasteWidget", test);
  frame.getJFrame().setPreferredSize(new Dimension(350, 200));
  frame.display();

}

See on the screen copies the result of such code ...

First display ...

CopyPaste1.jpg

User updating data ...

CopyPaste2.jpg

Copy & Paste these data ...

CopyPaste3.jpg

Reloading the widget ...

CopyPaste1.jpg

Paste data ...

CopyPaste4.jpg

We restored them !

CopyPaste2.jpg

Another way to do it

Rather than to use the label (or anything else) to attach the contextual menu, it is also possible to get this menu everywhere on your widget. To do it, you will just have to change these lines in the attachCopyPasteMenu() and after() methods:

  public void attachCopyPasteMenu (String title, CopyPasteOperation... operationList) {
    //lab.attachCopyPasteMenu(title, operationList);
    super.attachCopyPasteMenu(title, operationList);
  }
  
  public void after(GEvent arg0) throws GException {
		
    //boolean cpEvent = handleCopyPasteEvent(lab, arg0);
    boolean cpEvent = handleCopyPasteEvent(this, arg0);

}

CopyPaste5.jpg

But as sometimes, you may need to have several different "Copy & Paste" in the same GPanel : for example, one for the complete set of data and other ones for each data (or part of the data), it is important to know what you are going to copy or paste ! And it is precisely the role of the "title" argument : by given a not void character string, it will appear on the contextual menu.

  test.attachCopyPasteMenu("All the data", CopyPasteOperation.Copy, CopyPasteOperation.Paste);

CopyPaste51.jpg

More than Copy & Paste !

It is also possible to Import or Export these data into a file ans since V1.10 to reset the data. To do it, you will just have to add these operations when calling the attachCopyPasteMenu():

   test.attachCopyPasteMenu(null, CopyPasteOperation.Copy, CopyPasteOperation.Paste,
                            CopyPasteOperation.Import, CopyPasteOperation.Export, CopyPasteOperation.Reset);

Or, in order to have the whole possibilities:

   test.attachCopyPasteMenu(null, CopyPasteOperation.All);

CopyPaste6.jpg

Then a File manager will appear where we will have the possibility to choose our file.


Return to the introduction ↑ Go to the next page →