pax_global_header00006660000000000000000000000064130116166430014513gustar00rootroot0000000000000052 comment=6b687ef76236e79d43fe9b918a1d06fc357ac81e malai-2.0+ds1/000077500000000000000000000000001301161664300131225ustar00rootroot00000000000000malai-2.0+ds1/.gitignore000066400000000000000000000000151301161664300151060ustar00rootroot00000000000000*.class bin/ malai-2.0+ds1/README.md000066400000000000000000000026451301161664300144100ustar00rootroot00000000000000Malai ===== libMalai is a Java implementation of the Malai architectural design pattern. Malai can be viewed as an major step beyond MVC where the controller has been completely rethought to consider modern evolutions of the interactivity of systems. Malai can also be viewed as MVP architecture focusing on modern concerns: - More and more interactivity in software systems (with more and more post-WIMP interactions) - Multi-platform development thanks to its modularity Malai is based on the following HCI concepts: Norman's action model, instrumental interaction, direct manipulation, the interactor concept, and the DPI model. Research papers on Malai: - Blouin A. and Beaudoux O. Improving modularity and usability of interactive systems with Malai, EICS'10: Proceedings of the 2nd ACM SIGCHI symposium on Engineering interactive computing systems http://hal.archives-ouvertes.fr/docs/00/47/76/27/PDF/BLOUIN10a.pdf - Blouin A., Morin B., Beaudoux O., Nain G., Albers P., and Jézéquel J.-M. Combining Aspect-Oriented Modeling with Property-Based Reasoning to Improve User Interface Adaptation, EICS'11: Proceedings of the 3rd ACM SIGCHI symposium on Engineering interactive computing systems, 85-94 http://hal.inria.fr/inria-00590891/PDF/main.pdf - Blouin A. Un modèle pour l'ingénierie des systèmes interactifs dédiés à la manipulation de données, Ph.D. thesis http://tel.archives-ouvertes.fr/docs/00/44/63/14/PDF/these.pdf malai-2.0+ds1/malai-core/000077500000000000000000000000001301161664300151335ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/000077500000000000000000000000001301161664300204235ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/.classpath000066400000000000000000000010341301161664300224040ustar00rootroot00000000000000 malai-2.0+ds1/malai-core/org.malai.android/.gitignore000066400000000000000000000000151301161664300224070ustar00rootroot00000000000000/target /bin malai-2.0+ds1/malai-core/org.malai.android/.project000066400000000000000000000005701301161664300220740ustar00rootroot00000000000000 org.malai.android org.eclipse.jdt.core.javabuilder org.eclipse.jdt.core.javanature malai-2.0+ds1/malai-core/org.malai.android/.settings/000077500000000000000000000000001301161664300223415ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/.settings/org.eclipse.jdt.core.prefs000066400000000000000000000011131301161664300273170ustar00rootroot00000000000000eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.7 malai-2.0+ds1/malai-core/org.malai.android/pom.xml000066400000000000000000000056011301161664300217420ustar00rootroot00000000000000 4.0.0 org.malai malai.android 2.0 jar malai.swing :: Malai Android component src/main src/resources/ maven-assembly-plugin 2.4 src/assembly/assemblySrc.xml src/assembly/assemblyBin.xml make-assembly package single org.apache.maven.plugins maven-compiler-plugin 2.0.2 1.7 1.7 UTF-8 org.apache.felix maven-bundle-plugin 2.3.7 true methods 2 * org.malai malai.core 1.1 com.google.android android 4.1.1.4 provided mavenInriaSnapshot http://maven.inria.fr-snapshots http://maven.inria.fr/artifactory/malai-public-snapshot mavenInriaRelease http://maven.inria.fr-releases http://maven.inria.fr/artifactory/malai-public-release malai-2.0+ds1/malai-core/org.malai.android/src/000077500000000000000000000000001301161664300212125ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/assembly/000077500000000000000000000000001301161664300230315ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/assembly/assemblyBin.xml000066400000000000000000000016261301161664300260300ustar00rootroot00000000000000 bin zip ${project.build.directory} / ${project.artifactId}-${project.version}.jar true ${project.basedir} / license* true malai-2.0+ds1/malai-core/org.malai.android/src/assembly/assemblySrc.xml000066400000000000000000000014601301161664300260430ustar00rootroot00000000000000 src zip ${project.basedir} src/ compile license* pom.xml .classpath .gitignore .project .settings/ true malai-2.0+ds1/malai-core/org.malai.android/src/main/000077500000000000000000000000001301161664300221365ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/000077500000000000000000000000001301161664300227255ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/000077500000000000000000000000001301161664300240105ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/000077500000000000000000000000001301161664300254305ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/interaction/000077500000000000000000000000001301161664300277475ustar00rootroot00000000000000AndroidEventHandler.java000066400000000000000000000017641301161664300344230ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/interactionpackage org.malai.android.interaction; import android.widget.Button; /** * This interface can be used for object that want to gather Android events (button pressed, etc.) produced by HIDs.
*
* This file is part of Malai.
* Copyright (c) 2009-2013 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2013-02-26
* @author Arnaud BLOUIN * @since 0.2 */ public interface AndroidEventHandler { /** * Defines actions to do when a button is activated. * @param button The pressed button. * @since 0.2 */ void onButtonPressed(final Button button); } AndroidEventManager.java000066400000000000000000000046361301161664300344210ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/interactionpackage org.malai.android.interaction; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import org.malai.interaction.BasicEventManager; import org.malai.interaction.EventHandler; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; /** * An android event manager gathers Android events produces by widgets and transfers them handlers.
*
* This file is part of Malai.
* Copyright (c) 2009-2013 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2013-02-26
* @author Arnaud BLOUIN * @since 0.2 */ public class AndroidEventManager extends BasicEventManager implements OnClickListener { /** A subset of the set 'handlers' corresponding to the Android Handlers. */ private List androidHandlers; /** * Creates a event manager that gathers Android events and transfers them to handlers. * @since 0.2 */ public AndroidEventManager() { super(); androidHandlers = null; } /** * Attaches the SwingEventManager to the Java component to listen. * @param comp The Java Component to listen. */ public void attachTo(final View view) { if(view!=null) { view.setOnClickListener(this); } } @Override public void detachForm(final View view) { if(view!=null) { view.setOnClickListener(null); } } @Override public void addHandlers(final EventHandler h) { super.addHandlers(h); if(h instanceof AndroidEventHandler) { if(androidHandlers==null) androidHandlers = new CopyOnWriteArrayList<>(); androidHandlers.add((AndroidEventHandler)h); } } @Override public void removeHandler(final EventHandler h) { super.removeHandler(h); if(h!=null && androidHandlers!=null) androidHandlers.remove(h); } @Override public void onClick(final View view) { if(androidHandlers!=null && view instanceof Button) { Button button = (Button) view; for(final AndroidEventHandler handler : androidHandlers) handler.onButtonPressed(button); } } } AndroidInteraction.java000066400000000000000000000016001301161664300343100ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/interactionpackage org.malai.android.interaction; import org.malai.interaction.InitState; import org.malai.interaction.Interaction; import org.malai.stateMachine.ITransition; import android.widget.Button; public class AndroidInteraction extends Interaction implements AndroidEventHandler { public AndroidInteraction() { super(); } public AndroidInteraction(final InitState initState) { super(initState); } @Override public void onButtonPressed(final Button button) { if(!activated) return ; boolean again = true; ITransition t; for(int i=0, j=currentState.getTransitions().size(); i *
* This file is part of Malai.
* Copyright (c) 2009-2013 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2013-02-26
* @author Arnaud BLOUIN * @since 0.2 */ public class ButtonPressedTransition extends Transition { /** The pressed button. */ protected Button button; /** * {@link Transition#Transition(SourceableState, TargetableState)} */ public ButtonPressedTransition(final SourceableState inputState, final TargetableState outputState) { super(inputState, outputState); } /** * @return The pressed button. * @since 0.2 */ public Button getButton() { return button; } /** * Sets the pressed button. * @param button The pressed button. Must not be null. * @since 0.2 */ public void setButton(final Button button) { if(button!=null) this.button = button; } } malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/interaction/library/000077500000000000000000000000001301161664300314135ustar00rootroot00000000000000ButtonPressed.java000066400000000000000000000032221301161664300347770ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/interaction/librarypackage org.malai.android.interaction.library; import org.malai.android.interaction.AndroidInteraction; import org.malai.android.interaction.ButtonPressedTransition; import org.malai.interaction.TerminalState; import android.widget.Button; /** * A ButtonPressed interaction occurs when an Android button is pressed.
*
* This file is part of Malai.
* Copyright (c) 2009-2013 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2012-02-26
* @author Arnaud BLOUIN * @since 0.2 */ public class ButtonPressed extends AndroidInteraction { /** The pressed button. */ protected Button button; /** * Creates the interaction. */ public ButtonPressed() { super(); initStateMachine(); } @Override public void reinit() { super.reinit(); button = null; } @SuppressWarnings("unused") @Override protected void initStateMachine() { final TerminalState pressed = new TerminalState("pressed"); //$NON-NLS-1$ addState(pressed); new ButtonPressedTransition(initState, pressed) { @Override public void action() { super.action(); ButtonPressed.this.button = this.button; } }; } /** * @return The pressed button. * @since 0.2 */ public Button getButton() { return button; } } malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/widget/000077500000000000000000000000001301161664300267135ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.android/src/main/org/malai/android/widget/MButton.java000066400000000000000000000032601301161664300311470ustar00rootroot00000000000000package org.malai.android.widget; import org.malai.picking.Pickable; import org.malai.picking.Picker; import android.content.Context; import android.util.AttributeSet; import android.view.ViewParent; import android.widget.Button; /** * This widgets is based on an Android Button. It allows to be used in the Malai framework for picking.
*
* This file is part of Malai.
* Copyright (c) 2009-2013 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2012-02-26
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public class MButton extends Button implements Pickable { public MButton(Context ctx) { super(ctx); } public MButton(Context ctx, AttributeSet attrs) { super(ctx, attrs); } public MButton(Context ctx, AttributeSet attrs, int defStyle) { super(ctx, attrs, defStyle); } @Override public Picker getPicker() { ViewParent parent = getParent(); Picker picker = null; while(picker==null && parent!=null) if(parent instanceof Picker) picker = (Picker) parent; else parent = parent.getParent(); return picker; } @Override public boolean contains(double x, double y) { final float bx = getX(); final float by = getY(); return x>=bx && y>=by && x<=bx+getWidth() && y<=by+getHeight(); } } malai-2.0+ds1/malai-core/org.malai.core/000077500000000000000000000000001301161664300177335ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/.gitignore000066400000000000000000000000631301161664300217220ustar00rootroot00000000000000/target /out /bin /.settings /.classpath /.project malai-2.0+ds1/malai-core/org.malai.core/.idea/000077500000000000000000000000001301161664300207135ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/.idea/libraries/000077500000000000000000000000001301161664300226675ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/.idea/libraries/Maven__junit_junit_4_12.xml000066400000000000000000000006731301161664300277730ustar00rootroot00000000000000 malai-2.0+ds1/malai-core/org.malai.core/.idea/libraries/Maven__org_mockito_mockito_all_1_10_19.xml000066400000000000000000000010221301161664300326130ustar00rootroot00000000000000 malai-2.0+ds1/malai-core/org.malai.core/build.xml000066400000000000000000000037731301161664300215660ustar00rootroot00000000000000 malai-2.0+ds1/malai-core/org.malai.core/compile000077500000000000000000000000761301161664300213140ustar00rootroot00000000000000#! /bin/sh javac -d ./bin/ $(find ./src/org/* | grep .java$) malai-2.0+ds1/malai-core/org.malai.core/history.txt000066400000000000000000000034301301161664300221750ustar00rootroot00000000000000Version 2.0 - change: Instruments that use Swing widgets should inherits of the class SwingInstrument - change: Should use the interfaces Instrument, Interactor, and Interaction instead of their implementation class when possible. So, the classes Instrument, Interactor, and Interaction have been renamed as InstrumentImpl, InteractorImpl, and InteractionImpl. - change: API renaming: State, Transition -> StateImpl, TransitionImpl; IState, ITransition, IStateMachine -> State, Transition, StateMachine. - change: All the interactions and transitions based on key or mouse events have been moved from org.malai.core to org.malai.swing - change: All the interactions defined in the core module have been moved to org.malai.swing - change: Not necessary to catch interactor exceptions during their initialization in the operation Instrument::initialiseInteractors. ******************************************************************* Version 1.3 -- 2014-09-14 - fixed: some transitions of key-based interactions were always triggered - fixed: infinite loop when continuously pressing a key. - change: Link renamed as Interactor ******************************************************************* Version 1.2 - The executing of an action may provoke the execution of other actions. For instance with a drawing editor, one may want that after having pasting shapes, the new shapes must be selected. Thus, the action PasteShapes will be followed by an action SelectShapes. This is the goal of this feature. ******************************************************************* Version 1.1 - November 4th 2012 - Malai is now separated in several components (core, Swing, android, etc.) - Two interactions added to the library - Fixed: action not created when the last event of the interaction permits its creation. malai-2.0+ds1/malai-core/org.malai.core/license.txt000066400000000000000000000431261301161664300221240ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. malai-2.0+ds1/malai-core/org.malai.core/pom.xml000066400000000000000000000143261301161664300212560ustar00rootroot00000000000000 4.0.0 org.malai malai.core 2.0 jar malai.core :: Malai core library UTF-8 UTF-8 mavenInriaSnapshot http://maven.inria.fr-snapshots http://maven.inria.fr/artifactory/malai-public-snapshot mavenInriaRelease http://maven.inria.fr-releases http://maven.inria.fr/artifactory/malai-public-release src/main src/test/ src/resources/ maven-assembly-plugin 2.6 src/assembly/assemblySrc.xml src/assembly/assemblyBin.xml make-assembly package single org.apache.maven.plugins maven-compiler-plugin 3.5.1 1.8 1.8 UTF-8 org.apache.felix maven-bundle-plugin 2.3.7 true org.malai.* org.apache.maven.plugins maven-jar-plugin 2.6 false test-jar org.pitest pitest-maven 0.32 false org.malai.* test.org.malai.* org.mockito mockito-all 1.10.19 test junit junit 4.12 test malai-2.0+ds1/malai-core/org.malai.core/src/000077500000000000000000000000001301161664300205225ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/assembly/000077500000000000000000000000001301161664300223415ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/assembly/assemblyBin.xml000066400000000000000000000016751301161664300253440ustar00rootroot00000000000000 bin zip ${project.build.directory} / ${project.artifactId}-${project.version}.jar true ${project.basedir} / license* history.txt true malai-2.0+ds1/malai-core/org.malai.core/src/assembly/assemblySrc.xml000066400000000000000000000015271301161664300253570ustar00rootroot00000000000000 src zip ${project.basedir} src/ compile history.txt license* pom.xml .classpath .gitignore .project .settings/ true malai-2.0+ds1/malai-core/org.malai.core/src/debian/000077500000000000000000000000001301161664300217445ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/debian/README.Debian-source000066400000000000000000000026011301161664300253020ustar00rootroot00000000000000 Repackaging of original source for java-malai --------------------------------------------------------------------- java-imaging-utilities version 0.14.2+3. Downloaded file: java-imaging-utilities-0.14.2.tar.bz2 From: http://schmidt.devlib.org/jiu Path: java-imaging-utilities-0.14.2.tar.bz2 $ md5sum --binary java-imaging-utilities-0.14.2.tar.bz2 1b2e162344dac0ed219822f8ed8b658f *java-imaging-utilities-0.14.2.tar.bz2 The following commands were used to repackage the original source (the 'touch' commands ensure that the md5sum of the archives stays the same): $ mkdir java-imaging-utilities-0.14.2+3.orig $ tar -C java-imaging-utilities-0.14.2+3.orig -jxf java-imaging-utilities-0.14.2.tar.bz2 $ touch -t 199001010000.00 java-imaging-utilities-0.14.2+3.orig $ tar cf java-imaging-utilities_0.14.2+3.orig.tar --owner 0 --group 0 --numeric-owner --exclude=*.class --exclude=*.jar --exclude=*doc/api* --exclude=*.pdf java-imaging-utilities-0.14.2+3.orig $ touch -t 199001010000.00 java-imaging-utilities_0.14.2+3.orig.tar $ gzip -9 java-imaging-utilities_0.14.2+3.orig.tar $ md5sum --binary java-imaging-utilities_0.14.2+3.orig.tar.gz 814d36fe5f6443fb7910973c132d870e *java-imaging-utilities_0.14.2+3.orig.tar.gz -- Stuart Prescott Mon, 20 Apr 2009 01:10:13 +0100 --------------------------------------------------------------------- malai-2.0+ds1/malai-core/org.malai.core/src/debian/build.xml000066400000000000000000000031051301161664300235640ustar00rootroot00000000000000 malai-2.0+ds1/malai-core/org.malai.core/src/debian/changelog000066400000000000000000000002351301161664300236160ustar00rootroot00000000000000java-malai (0.2-1) unstable; urgency=low * Initial packaging efforts. -- Arnaud BLOUIN Wed, 24 Oct 2012 12:30:04 +0100 malai-2.0+ds1/malai-core/org.malai.core/src/debian/compat000066400000000000000000000000021301161664300231420ustar00rootroot000000000000007 malai-2.0+ds1/malai-core/org.malai.core/src/debian/control000066400000000000000000000017131301161664300233510ustar00rootroot00000000000000Source: java-malai Section: java Priority: optional Maintainer: Arnaud BLOUIN Build-Depends: debhelper (>= 7.0.50~) Build-Depends-Indep: java-gcj-compat-dev, ant Standards-Version: 3.9.3 DM-Upload-Allowed: yes Package: libmalai-java Architecture: all Depends: ${misc:Depends} Suggests: libmalai-java-doc Description: Java implementation of the Malai architectural design pattern. . Malai can be viewed as an major step beyond MVC where the controller has been completely rethought to consider modern evolutions of the interactivity of systems. Package: libmalai-java-doc Architecture: all Section: doc Depends: default-jdk-doc, ${misc:Depends} Description: API documentation for malai java library Malai is an architectural design pattern for developing interactive systems. . This package contains the API documentation for the library. . See the package libmalai-java for further information. malai-2.0+ds1/malai-core/org.malai.core/src/debian/copyright000066400000000000000000000014161301161664300237010ustar00rootroot00000000000000Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Malai Upstream-Contact: Arnaud BLOUIN Source: https://launchpad.net/malai/ Comment: The compiled java (*.class) and archives (*.jar) were stripped from the downloaded file to create the 'orig' source package. See the file README.Debian-source for full details. Files: * Copyright: © 2009-2012, Arnaud BLOUIN License: GPL-2 Files: debian/* Copyright: © 2009-2012, Stuart Prescott , Arnaud BLOUIN License: GPL-2 License: GPL-2 On Debian systems, the complete text of the GNU General Public License, version 2, can be found in /usr/share/common-licenses/GPL-2. malai-2.0+ds1/malai-core/org.malai.core/src/debian/libmalai-java-doc.doc-base000066400000000000000000000006731301161664300266050ustar00rootroot00000000000000Document: malai Title: Java implementation of the Malai model dedicated to the conception of interactive systems Author: Arnaud BLOUIN Abstract: This manual contains the API documentation for the malai library for dedicated to the conception of interactive systems in Java Section: Java Format: HTML Index: /usr/share/doc/libmalai-java-doc/api/index.html Files: /usr/share/doc/libmalai-java-doc/api/*.html malai-2.0+ds1/malai-core/org.malai.core/src/debian/libmalai-java-doc.docs000066400000000000000000000000371301161664300260520ustar00rootroot00000000000000debian/README.Debian-source apimalai-2.0+ds1/malai-core/org.malai.core/src/debian/libmalai-java.dirs000066400000000000000000000000351301161664300253160ustar00rootroot00000000000000usr/share/java usr/share/doc malai-2.0+ds1/malai-core/org.malai.core/src/debian/libmalai-java.docs000066400000000000000000000000541301161664300253060ustar00rootroot00000000000000README debian/README.Debian-source doc/TODO malai-2.0+ds1/malai-core/org.malai.core/src/debian/repackage000077500000000000000000000164641301161664300236270ustar00rootroot00000000000000#!/bin/sh set -u set -e # set -x if [ -f ~/.devscripts ] then . ~/.devscripts fi PACKAGE=frobinator UPSTREAM=sourceforge.net UNARCHIVE=do_unzip WRAPDIR=true LOG=README.Debian-source VERBOSE=${VERBOSE:-1} CLEANUP=${CLEANUP:-0} SCRIPTDIR=$(dirname $(readlink -f $0)) NAME=$(basename $0) RCFILE=$SCRIPTDIR/repackagerc EXCLUDE_LIST="" # Originally '197001010000.00' but tar complains about an # "implausibly old time stamp" TOUCHTIME=199001010000.00 # Set a consistent umask for repackaging so that the tarball is reproducible # (overridable in the rc file) umask 002 usage() { cat <&2 Usage: $NAME --upstream-version x.y.z filename.zip [src_package_revision] [target_dir] Where the the version x.y.z is the version number of the new version and filename.zip (or .tar.gz or whatever) is the new source filename for the package $PACKAGE. If filename.zip starts with http:// or ftp:// then wget is used to download the archive first. The file $RCFILE must exist and set the following environment variables (and these are their current versions): PACKAGE=$PACKAGE UPSTREAM=$UPSTREAM UNARCHIVE=$UNARCHIVE EXCLUDE_LIST=$EXCLUDE_LIST (EXCLUDE_LIST is a list of exclusions for tar, one per line. Note that spaces in path names are problematic) It is expected that this utility is run by uscan or and is run in the base directory of the source package. The optional argument 'src_package_revision' can be specified to indicate additional cycles of source package revision that may have been undertaken in addition to the regular packaging activities. If not specified, the debian/changelog is parsed to try to work out what the source revision should be. The optional argument 'target_dir' may be used to specify where the repackaged source should be left. EOT } progress() { if [ "$VERBOSE" != 0 -a -n $VERBOSE ] then echo "$@" fi } logmsg() { echo "$@" >> $LOGFILE } logcmd() { logcmdpieces "$@" "$@" >> $LOGFILE } # This is a truly appalling hack, but the only sensible way to # maintain proper quoting in the log, it seems, unless each command is # double quoted to begin with... which is also an ugly, bug-attracting # hack. logcmdpieces() { printf "\n$ " >> $LOGFILE echo "$@" >> $LOGFILE } carp() { echo "E: ($NAME) $*" exit 1 } do_unzip() { logcmd unzip -qq -d "$1" "$2" } do_untargz() { logcmd tar -C "$1" -zxf "$2" } do_untarbz2() { logcmd tar -C "$1" -jxf "$2" } testarchive() { case "$1" in do_unzip) ALLDIRS=$(zipinfo -1 "$2" | cut -f1 -d/ | sort -u) if [ $(echo "$ALLDIRS" | wc -l) -gt 1 ] then testarchiveerror fi echo "$ALLDIRS" ;; do_untargz) ALLDIRS=$(tar ztf "$2" | cut -f1 -d/ | sort -u) if [ $(echo "$ALLDIRS" | wc -l) -gt 1 ] then testarchiveerror fi echo "$ALLDIRS" ;; do_untarbz2) ALLDIRS=$(tar jtf "$2" | cut -f1 -d/ | sort -u) if [ $(echo "$ALLDIRS" | wc -l) -gt 1 ] then testarchiveerror fi echo "$ALLDIRS" ;; esac } testarchiveerror() { echo "E: More than one directory was found in the unwrapped archive." echo "E: Set WRAPDIR to wrap the contents of the tarball in a directory." exit 1 } make_exclude_list() { echo "$EXCLUDE_LIST" | grep -v -e ^$ | sed 's/^\(.*\)/--exclude=\1/' } next_source_version() { LAST_SRC=$(dpkg-parsechangelog | \ sed -n 's/Version: \(.*\)+[0-9\-]*/\1/p') #echo "LS=$LAST_SRC" if [ $LAST_SRC = $VERSION ] then SRCVERSION=$(dpkg-parsechangelog | \ sed -n 's/Version: [^+]*+\(.*\)-.*/\1/p') SRCVERSION=$(($SRCVERSION+1)) else SRCVERSION=1 fi echo $SRCVERSION } ########################################################################### if [ ! -f $RCFILE ] then cat <&2 $0 Error: No configuration parameters found in file $RCFILE. Exiting. EOT usage exit 1 fi # Read in the user/package settings . $RCFILE if [ $# -lt 3 -o $# -gt 5 ] then usage exit 1 fi ########################################################################### DATE=$(date -R) VERSION=$2 SRCPATH=$3 SRCVERSION="" TARGETDIR=$(pwd) if [ $# -eq 5 ] then SRCVERSION="$4" TARGETDIR="$5" elif [ $# -eq 4 ] then if [ -d $4 ] then TARGETDIR="$4" SRCVERSION=$(next_source_version) else SRCVERSION="$4" fi else SRCVERSION=$(next_source_version) fi VERSION="$VERSION+$SRCVERSION" if [ ! -d "$TARGETDIR" ] then carp "Target directory '$TARGETDIR' doesn't exist!" fi progress "I: Making orig tarball for $VERSION" ########################################################################### LOGFILE=$TARGETDIR/$LOG if [ -f "$LOGFILE" ] then progress "W: Deleting existing log file" rm "$LOGFILE" fi ########################################################################### DIR=${PACKAGE}-$VERSION.orig ARCHIVEFILE=${PACKAGE}_${VERSION}.orig.tar ARCHIVELOCATION="$TARGETDIR" TEMPDIR=$(mktemp -t -d $NAME.XXXXXXXXXX) || carp "Couldn't make temp dir" ########################################################################### progress "I: Locating source $SRCPATH" SRCARCHIVE=$(basename "$SRCPATH") if [ $(expr substr "$SRCPATH" 1 7) = "http://" -o \ $(expr substr "$SRCPATH" 1 6) = "ftp://" ] then UPSTREAMURL="$SRCPATH" wget "$UPSTREAMURL" -O "$TEMPDIR/$SRCARCHIVE" else cp "$SRCPATH" "$TEMPDIR" fi cd $TEMPDIR || carp "Couldn't cd to temp dir $TEMPDIR" ########################################################################### MD5="md5sum --binary" logmsg " Repackaging of original source for $PACKAGE --------------------------------------------------------------------- $PACKAGE version $VERSION. Downloaded file: $SRCARCHIVE From: $UPSTREAM Path: $SRCPATH" logcmd $MD5 $SRCARCHIVE progress "I: Directory: $DIR I: Package name: $PACKAGE I: Version: $VERSION" logmsg " The following commands were used to repackage the original source (the 'touch' commands ensure that the md5sum of the archives stays the same):" # get the source progress "I: Uncompressing source" if $WRAPDIR then logcmd mkdir $DIR $UNARCHIVE $DIR $SRCARCHIVE else INNERDIR=$(testarchive $UNARCHIVE $SRCARCHIVE) $UNARCHIVE . $SRCARCHIVE logcmd mv $INNERDIR $DIR fi # set a consistent time for the top directory logcmd touch -t $TOUCHTIME $DIR # repackage the archive progress "I: Creating 'orig' tar archive" #echo "$(make_exclude_list)" logcmd tar cf $ARCHIVEFILE --owner 0 --group 0 --numeric-owner \ $(make_exclude_list) \ $DIR # Also set a consistent time on the tar archive logcmd touch -t $TOUCHTIME $ARCHIVEFILE #logcmd md5sum $ARCHIVEFILE progress "I: Compressing archive" logcmd gzip -9 $ARCHIVEFILE logcmd md5sum --binary $ARCHIVEFILE.gz logmsg " -- $DEBFULLNAME <$DEBEMAIL> $DATE --------------------------------------------------------------------- " ########################################################################### progress "I: Moving archive $ARCHIVEFILE.gz" #mv $ARCHIVEFILE $ARCHIVELOCATION touch $ARCHIVEFILE.gz mv $ARCHIVEFILE.gz $ARCHIVELOCATION ########################################################################### if [ $CLEANUP != 0 ] then progress "I: Cleaning up $TEMPDIR" rm -rf $TEMPDIR else progress "I: Files left in $TEMPDIR for your inspection" fi ########################################################################### malai-2.0+ds1/malai-core/org.malai.core/src/debian/repackagerc000066400000000000000000000003221301161664300241330ustar00rootroot00000000000000# Settings for repackaging the upstream source code # of the Malai library package PACKAGE=java-malai UPSTREAM=https://launchpad.net/malai UNARCHIVE=do_untarbz2 EXCLUDE_LIST=" *.class *.jar *doc/api* *.pdf " malai-2.0+ds1/malai-core/org.malai.core/src/debian/rules000077500000000000000000000026311301161664300230260ustar00rootroot00000000000000#!/usr/bin/make -f # Uncomment this to turn on verbose mode. # export DH_VERBOSE=1 # Create versioned jar file; strip off the debian source revision and package revision VERSION=$(shell dpkg-parsechangelog | sed -n 's/Version: \([0-9.]*\).*/\1/p') # If the user has not explicitly set JAVA_HOME, export sensible value # to make sure that the correct compiler is used by ant. JAVA_HOME ?= /usr/lib/jvm/java-gcj export JAVA_HOME PREFIX=debian/libmalai-java %: dh $@ override_dh_auto_clean: find . -name \*.jar -exec rm -f {} \; find . -name \*.class -exec rm -f {} \; rm -rf out bin api override_dh_auto_build: mkdir out bin ant -Dbasedir=. -f debian/build.xml compile ant -Dbasedir=. -f debian/build.xml jar doc override_dh_install: cp out/malai.jar $(PREFIX)/usr/share/java/org.malai-$(VERSION).jar override_dh_link: dh_link usr/share/java/org.malai-$(VERSION).jar usr/share/java/org.malai.jar # Be explicit given that there is plenty of confusion about what this target means get-orig-source: get-latest-source get-latest-source: cd $(dir $_).. && \ uscan=$$(uscan --report --dehs --upstream-version 0) && \ uver=$$(echo "$$uscan" | sed -n 's,\(.*\),\1,p') && \ uurl=$$(echo "$$uscan" | sed -n 's,\(.*\),\1,p') && \ echo debian/repackage --upstream-version "$${uver}" "$${uurl}" $(CURDIR) &&\ sh debian/repackage --upstream-version "$${uver}" "$${uurl}" $(CURDIR) malai-2.0+ds1/malai-core/org.malai.core/src/debian/source/000077500000000000000000000000001301161664300232445ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/debian/source/format000066400000000000000000000000141301161664300244520ustar00rootroot000000000000003.0 (quilt) malai-2.0+ds1/malai-core/org.malai.core/src/debian/watch000066400000000000000000000003271301161664300227770ustar00rootroot00000000000000# upstream website has disappeared version=3 #opts="dversionmangle=s/\+\d+$//" \ #http://schmidt.devlib.org/jiu/download.html \ # java-imaging-utilities-(.*)\.tar\.bz2 \ # debian \ # debian/repackage malai-2.0+ds1/malai-core/org.malai.core/src/main/000077500000000000000000000000001301161664300214465ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/000077500000000000000000000000001301161664300222355ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/000077500000000000000000000000001301161664300233205ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/000077500000000000000000000000001301161664300245755ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/Action.java000066400000000000000000000113661301161664300266640ustar00rootroot00000000000000package org.malai.action; import java.util.Collections; import java.util.List; /** * An action is based on the command design pattern: it is an object that * encapsulates information to execute a task and to undo/redo it if * necessary.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* @author Arnaud BLOUIN * @since 0.2 */ public abstract class Action { /** Defines the different state of the action. @since 0.2 */ public static enum ActionStatus { /** When the action is created but not executed yet. */ CREATED, /** When the action has been created and executed one time. */ EXECUTED, /** When the action has been aborted. */ ABORTED, /** When the action has been defined as done. */ DONE, /** The the action has been flushed. In this case, the action cannot be used anymore. */ FLUSHED } /** Provides the state of the action. */ protected ActionStatus status; /** * The default constructor. */ public Action() { super(); status = ActionStatus.CREATED; } /** * When an action is no more useful it can be flushes to release the used data. * Should be overridden. * @since 0.2 */ public void flush() { status = ActionStatus.FLUSHED; } /** * Specifies if the action must be saved in the action register. For instance, * some actions, such as a scroll of the scroll bars, should not be saved nor * put in the undo/redo manager. Thus, they must not be registrable. * @return True: the action is registrable. * @since 0.1 */ public abstract boolean isRegisterable(); /** * Executes the action. Should be overridden by sub-class to define stuffs to execute. * If the status of the action differs than CREATED or EXECUTED and if the action cannot be done (canDo), * the action is not executed. * @since 0.1 * @return True if the execution is successful. False otherwise. */ public boolean doIt() { final boolean ok; if((status==ActionStatus.CREATED || status==ActionStatus.EXECUTED) && canDo()) { ok = true; doActionBody(); status = ActionStatus.EXECUTED; ActionsRegistry.INSTANCE.onActionExecuted(this); } else ok = false; return ok; } /** * This method contains the core code to execute when the action is executed. * @since 0.1 */ protected abstract void doActionBody(); /** * @return True if the action can be executed. * @since 0.1 */ public abstract boolean canDo(); /** * @return True if the execution of the action had effects on the target. * By default this function return the result of isDone. Should be overridden. * @since 0.1 */ public boolean hadEffect() { return isDone(); } /** * Defines if the given action can cancel the calling action. Should be overridden. * By default, false is returned. * @param action The action to test. * @return True if the given action cancels the calling action. By default, false is returned. * @since 0.1 */ public boolean cancelledBy(final Action action) { return false; } /** * Sets the action to "done". * @since 0.1 */ public void done() { if(status==ActionStatus.CREATED || status==ActionStatus.EXECUTED) { status = ActionStatus.DONE; ActionsRegistry.INSTANCE.onActionDone(this); } } /** * @return True if the action is done. * @since 0.1 */ public boolean isDone() { return status==ActionStatus.DONE; } @Override public String toString() { return getClass().getSimpleName(); } /** * Aborts the action. * @since 0.1 */ public void abort() { status = ActionStatus.ABORTED; } /** * Provides the state of the action. * @return The state of the action. * @since 0.2 */ public ActionStatus getStatus() { return status; } /** * The executing of an action may provoke the execution of other actions.
* For instance with a drawing editor, one may want that after having pasting * shapes, the new shapes must be selected. * Thus, the action PasteShapes will be followed by an action SelectShapes.
* This is the goal of the operation.
* This operation creates an initialises the action that will be executed after * each final execution of the current action. * @return A list of actions that must be executed afterward. Cannot be null. */ public List followingActions() { return Collections.emptyList(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/ActionHandler.java000066400000000000000000000033101301161664300301500ustar00rootroot00000000000000package org.malai.action; import org.malai.undo.UndoHandler; /** * This interface allows to create a bridge between an action and an * object that want to be aware about events on actions (such as creation or * deletion of an action).
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* @author Arnaud Blouin * @since 0.1 */ public interface ActionHandler extends UndoHandler { /** * Notifies the handler when the given action is cancelled. * @param action The cancelled action. * @since 0.2 */ void onActionCancelled(final Action action); /** * Notifies the handler when the given action is added to the registry. * @param action The added action. * @since 0.2 */ void onActionAdded(final Action action); /** * Notifies the handler when the given action is aborted. * @param action The aborted action. * @since 0.2 */ void onActionAborted(final Action action); /** * Notifies the handler when the given action is executed. * @param action The executed action. * @since 0.2 */ void onActionExecuted(final Action action); /** * Notifies the handler when the given action is done. * @param action The action that ends. * @since 0.2 */ void onActionDone(final Action action); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/ActionsRegistry.java000066400000000000000000000133011301161664300305670ustar00rootroot00000000000000package org.malai.action; import java.util.ArrayList; import java.util.List; import org.malai.undo.UndoCollector; import org.malai.undo.Undoable; /** * A register of actions.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud Blouin * @since 0.1 */ public final class ActionsRegistry { /** The saved actions. */ private final List actions; /** The actions handlers. */ private final List handlers; /** The max number of actions that can contains the register. */ private int sizeMax; /** The register of actions. */ public static final ActionsRegistry INSTANCE = new ActionsRegistry(); /** * Creates and initialises a register. * @since 0.1 */ private ActionsRegistry() { super(); actions = new ArrayList<>(); handlers = new ArrayList<>(); sizeMax = 30; } /** * Notifies handlers that an action has been executed. * @param action The executed action. * @since 0.2 */ public void onActionExecuted(final Action action) { if(action!=null) for(final ActionHandler handler : handlers) handler.onActionExecuted(action); } /** * Notifies handlers that an action ends. * @param action The action that ends. * @since 0.2 */ public void onActionDone(final Action action) { if(action!=null) for(final ActionHandler handler : handlers) handler.onActionDone(action); } /** * @return The stored actions. Cannot be null. * @since 0.1 */ public List getActions() { return actions; } /** * Removes and flushes actions from the register using a given action. * @param action The action that may cancels others. * @since 0.1 */ public void cancelActions(final Action action) { if(action==null) return; int i=0; while(i0) { cancelActions(action); // If there is too many actions in the register, the oldest action is removed and flushed. if(actions.size()==sizeMax) actions.remove(0).flush(); actions.add(action); for(final ActionHandler handler : handlers) handler.onActionAdded(action); if(action instanceof Undoable) UndoCollector.INSTANCE.add((Undoable)action, actionHanndler); } } /** * Removes the action from the register. The action is then flushes. * @param action The action to remove. * @since 0.1 */ public void removeAction(final Action action) { if(action==null) return; actions.remove(action); action.flush(); } /** * Adds an action handler. * @param handler The handler to add. * @since 0.1 */ public void addHandler(final ActionHandler handler) { if(handler!=null) handlers.add(handler); } /** * Removes the given handler. * @param handler The handler to remove. * @since 0.2 */ public void removeHandler(final ActionHandler handler) { if(handler!=null) handlers.remove(handler); } /** * Removes all the action handlers. * @since 0.2 */ public void removeAllHandlers() { handlers.clear(); } /** * Removes all the stored actions. * @since 0.2 */ public void clear() { while(!actions.isEmpty()) actions.remove(0).flush(); } /** * @param clazz The reference class. * @return The first action of the exact same class of the given class. * @since 0.1 */ public T getAction(final Class clazz) { T action = null; if(clazz!=null) for(int i=0, size=actions.size(); i=0) { // If there is too many actions in the register, they are removed. for(int i=0, nb=actions.size()-sizeMax; i *
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud Blouin * @since 0.2 */ public class ActivateInstrument extends InstrumentAction { /** * {@link InstrumentAction#InstrumentAction()} */ public ActivateInstrument() { super(); } @Override protected void doActionBody() { instrument.setActivated(true); } @Override public boolean isRegisterable() { return false; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/AnonymousAction.java000066400000000000000000000017651301161664300322430ustar00rootroot00000000000000package org.malai.action.library; import org.malai.action.Action; /** * An anonymous class that permits to create an action without defining a specific Action class. * A runnable, corresponding to the body of the action has to be provided to the action. * Created by Arnaud Blouin on 18/07/16. */ public class AnonymousAction extends Action { /** The runnable executed when the action is executed. */ protected Runnable actionBody; /** Create the action. */ public AnonymousAction() { super(); } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { actionBody.run(); } @Override public boolean canDo() { return actionBody!=null; } /** * Sets the runnable of the action. * @param body The runnable executed when the action is executed. */ public void setActionBody(final Runnable body) { actionBody = body; } /** * @return The runnable of the action. */ public Runnable getActionBody() { return actionBody; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/InactivateInstrument.java000066400000000000000000000017371301161664300332740ustar00rootroot00000000000000package org.malai.action.library; /** * This action inactivates an instrument.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud Blouin * @since 0.2 */ public class InactivateInstrument extends InstrumentAction { /** * {@link InstrumentAction#InstrumentAction()} */ public InactivateInstrument() { super(); } @Override protected void doActionBody() { instrument.setActivated(false); } @Override public boolean isRegisterable() { return false; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/InstrumentAction.java000066400000000000000000000026511301161664300324160ustar00rootroot00000000000000package org.malai.action.library; import org.malai.action.Action; import org.malai.instrument.Instrument; /** * This action manipulates an instrument.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud Blouin * @since 0.2 */ public abstract class InstrumentAction extends Action { /** The manipulated instrument. */ protected Instrument instrument; /** * Creates the action. * @since 0.2 */ public InstrumentAction() { super(); } @Override public void flush() { super.flush(); instrument = null; } @Override public boolean canDo() { return instrument!=null; } /** * @return The manipulated instrument. * @since 0.2 */ public Instrument getInstrument() { return instrument; } /** * Sets the manipulated instrument. * @param instrument The manipulated instrument. * @since 0.2 */ public void setInstrument(final Instrument instrument) { this.instrument = instrument; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/ModifyValue.java000066400000000000000000000040641301161664300313340ustar00rootroot00000000000000package org.malai.action.library; import org.malai.action.Action; /** * The goal of this abstract action is to modify an object. This object can be for instance * a property of an object.
* The use of this action can be made when an object has a lot of properties which modification * follow the same process. Thus, a same action can be used to modify all the properties. To do * so, a enumeration of the properties can be defined and used into the action to specify which * property will be modified by the current action instance. *
* This file is part of Malai
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version.
*
* Malai is distributed without any warranty; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details.
*
* @author Arnaud Blouin * @since 0.2 */ public abstract class ModifyValue extends Action { /** The new value of the property. */ protected Object value; /** * Initialises the action. * @since 0.2 */ public ModifyValue() { super(); } @Override public void flush() { super.flush(); value = null; } @Override public boolean canDo() { return value!=null && isValueMatchesProperty(); } /** * Sets the new value of the parameter to change. * @param value The new value. * @since 0.2 */ public void setValue(final Object value) { this.value = value; } /** * This method executes the job of methods undo, redo, and do * @param obj The value to set. Must not be null. * @throws NullPointerException If the given value is null. * @since 0.2 */ protected abstract void applyValue(final Object obj); /** * @return True: the object to modified supports the selected property. * @since 0.2 */ protected abstract boolean isValueMatchesProperty(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/OpenWebPage.java000066400000000000000000000032341301161664300312420ustar00rootroot00000000000000package org.malai.action.library; import java.awt.Desktop; import java.io.IOException; import java.net.URI; import org.malai.action.Action; /** * This action opens an URI in the default browser.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 08/11/2011
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public class OpenWebPage extends Action { /** The URI to open. */ protected URI uri; private boolean browsed; /** * Creates the action. * @since 0.2 */ public OpenWebPage() { super(); browsed = false; } @Override public boolean isRegisterable() { return false; } @Override public void flush() { uri = null; } @Override protected void doActionBody() { try{ Desktop.getDesktop().browse(uri); browsed = true; }catch(IOException exception){ browsed = false; } } @Override public boolean canDo() { return uri!=null && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE); } @Override public boolean hadEffect() { return super.hadEffect() && browsed; } /** * @param uri The URI to open. * @since 0.2 */ public void setUri(final URI uri) { this.uri = uri; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/PositionAction.java000066400000000000000000000026301301161664300320470ustar00rootroot00000000000000package org.malai.action.library; import org.malai.action.Action; /** * Defines an abstract action that move an object to the given position.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 12/20/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public abstract class PositionAction extends Action { /** The X-coordinate of the location to zoom. */ protected double px; /** The Y-coordinate of the location to zoom. */ protected double py; /** * Creates the action. */ public PositionAction() { super(); px = Double.NaN; py = Double.NaN; } @Override public boolean canDo() { return !Double.isNaN(px) && !Double.isNaN(py); } /** * @param px The x-coordinate to set. * @since 0.2 */ public void setPx(final double px) { this.px = px; } /** * @param py The y-coordinate to set. * @since 0.2 */ public void setPy(final double py) { this.py = py; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/Redo.java000066400000000000000000000022171301161664300277770ustar00rootroot00000000000000package org.malai.action.library; import org.malai.action.Action; import org.malai.undo.UndoCollector; /** * Defines an action that redoes an action.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/10/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public class Redo extends Action { /** * Initialises a Redo action. * @since 0.2 */ public Redo() { super(); } @Override public boolean canDo() { return UndoCollector.INSTANCE.getLastRedo()!=null; } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { UndoCollector.INSTANCE.redo(); done(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/Undo.java000066400000000000000000000022161301161664300300120ustar00rootroot00000000000000package org.malai.action.library; import org.malai.action.Action; import org.malai.undo.UndoCollector; /** * Defines an action that undoes an action.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/10/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public class Undo extends Action { /** * Initialises an Undo action. * @since 0.2 */ public Undo() { super(); } @Override public boolean canDo() { return UndoCollector.INSTANCE.getLastUndo()!=null; } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { UndoCollector.INSTANCE.undo(); done(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/action/library/Zoom.java000066400000000000000000000033041301161664300300300ustar00rootroot00000000000000package org.malai.action.library; import org.malai.properties.Zoomable; /** * Defines an action that zoom int/out a panel.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/11/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public class Zoom extends PositionAction { /** The object to zoom. */ protected Zoomable zoomable; /** The zooming level. */ protected double zoomLevel; /** * Initialises a Zoom action. * @since 0.2 */ public Zoom() { super(); zoomLevel = Double.NaN; zoomable = null; } @Override public void flush() { super.flush(); zoomable = null; } @Override public boolean canDo() { return zoomable!=null && zoomLevel>=zoomable.getMinZoom() && zoomLevel<=zoomable.getMaxZoom(); } @Override protected void doActionBody() { zoomable.setZoom(px, py, zoomLevel); } @Override public boolean isRegisterable() { return false; } /** * @param zoomable the zoomable to set. * @since 0.2 */ public void setZoomable(final Zoomable zoomable) { this.zoomable = zoomable; } /** * @param zoomLevel the zoomLevel to set. * @since 0.2 */ public void setZoomLevel(final double zoomLevel) { this.zoomLevel = zoomLevel; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/error/000077500000000000000000000000001301161664300244515ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/error/ErrorCatcher.java000066400000000000000000000041301301161664300276750ustar00rootroot00000000000000package org.malai.error; /** * The singleton ErrorCatcher permits to Malai code to send errors to a gatherer. * The ErrorCatcher then send the catched exception to an ErrorNotifier (if one is * defined). This is useful to gather Malai errors into a third-part application. * For instance, a develope can define his own error manager which implements * the ErrorNotifier interface and which is registered to the ErrorCatcher in order * to manage both the Malai exceptions and the third-part application errors.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 07/23/2011
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public final class ErrorCatcher { /** The singleton ErrorCatcher. */ public static final ErrorCatcher INSTANCE = new ErrorCatcher(); /** The notifier object. */ private ErrorNotifier notifier; /** * Creates the error catcher. */ private ErrorCatcher() { super(); } /** * Sets the notifier that will be notified about Malai errors. * @param notifier The notifier that will be notified about errors. Can be null. * @since 0.2 */ public void setNotifier(final ErrorNotifier notifier) { this.notifier = notifier; } /** * @return The notifier that is notified about errors. * @since 0.2 */ public ErrorNotifier getErrorNotifier() { return notifier; } /** * Gathers malai exceptions. * @param exception The errors to gather. Nothing is done if null or if no * notifier is defined. * @since 0.1 */ public void reportError(final Exception exception) { if(exception!=null && notifier!=null) notifier.onMalaiException(exception); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/error/ErrorNotifier.java000066400000000000000000000017531301161664300301130ustar00rootroot00000000000000package org.malai.error; /** * This interface must be used by error gatherer of third-part applications * that want to gather Malai's exceptions.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 07/23/2011
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface ErrorNotifier { /** * Notifies that an exception has been thrown in the Malai code. * @param exception The thrown exception. * @since 0.2 */ void onMalaiException(final Exception exception); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/instrument/000077500000000000000000000000001301161664300255305ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/instrument/Instrument.java000066400000000000000000000042601301161664300305450ustar00rootroot00000000000000package org.malai.instrument; import java.util.List; import org.malai.action.ActionHandler; import org.malai.interaction.Eventable; import org.malai.preferences.Preferenciable; import org.malai.properties.Modifiable; import org.malai.properties.Reinitialisable; /** * An interface defining the concept of instrument and its related services.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 2014-09-19 * @version 2.0 */ public interface Instrument extends Preferenciable, Modifiable, Reinitialisable, ActionHandler { /** * @return The number of interactors that compose the instrument. * @since 0.2 */ int getNbInteractors(); /** * @return True: the instrument has at least one interactor. False otherwise. * @since 0.2 */ boolean hasInteractors(); /** * @return The interactors that compose the instrument. Cannot be null. * @since 0.2 */ List getInteractors(); /** * Binds the interaction of the interactors of the instrument to a Eventable object that produces * events used by the interactions. * @param eventable The eventable object that gathers event used by the interactions. * @since 0.2 */ void addEventable(Eventable eventable); /** * Stops the interactions of the instrument and clears all its events waiting for a process. * @since 0.2 */ void clearEvents(); /** * @return True if the instrument is activated. */ boolean isActivated(); /** * Activates or deactivates the instrument. * @param activated True = activation. */ void setActivated(boolean activated); /** * Reinitialises the interim feedback of the instrument. * Must be overridden. */ void interimFeedback(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/instrument/InstrumentImpl.java000066400000000000000000000124761301161664300313770ustar00rootroot00000000000000package org.malai.instrument; import java.util.ArrayList; import java.util.List; import org.malai.action.Action; import org.malai.error.ErrorCatcher; import org.malai.interaction.Eventable; import org.malai.undo.Undoable; import org.w3c.dom.Document; import org.w3c.dom.Element; /** * Defines an abstract model of an instrument.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* * @author Arnaud BLOUIN * @date 05/24/10 * @since 0.1 * @version 0.2 */ public abstract class InstrumentImpl implements Instrument { /** Defines if the instrument is activated or not. */ protected boolean activated; /** The interactors of the instrument. */ protected final List interactors; /** Defined if the instrument has been modified. */ protected boolean modified; /** The eventable objects that the instrument uses. */ protected List eventables; /** * Creates and initialises the instrument. * @since 0.1 */ public InstrumentImpl() { activated = false; modified = false; interactors = new ArrayList<>(); } @Override public int getNbInteractors() { return interactors.size(); } @Override public boolean hasInteractors() { return getNbInteractors()>0; } @SuppressWarnings("unchecked") @Override public List getInteractors() { return (List) interactors; } /** * Initialises the interactors of the instrument. * @throws InstantiationException When an interactor cannot instantiate its interaction. * @throws IllegalAccessException When an interactor cannot instantiate its interaction. * @since 0.2 */ protected abstract void initialiseInteractors() throws InstantiationException, IllegalAccessException; /** * Adds the given interactor to the list of interactors of the instrument. * Eventables object previously added to the instrument are added * to the added interactor. * @param interactor The interactor to add. If null, nothing is done. * @since 0.2 */ protected void addInteractor(final T interactor) { if(interactor!=null) { interactors.add(interactor); interactor.setActivated(isActivated()); if(eventables!=null) for(final Eventable eventable : eventables) interactor.addEventable(eventable); } } /** * Removes the given interactor from the list of interactors of the instrument. * @param interactor The interactor to remove. * @return True: the given interactor has been removed. False otherwise. * @since 0.2 */ protected boolean removeInteractor(final T interactor) { return interactor==null ? false : interactors.remove(interactor); } @Override public void addEventable(final Eventable eventable) { if(eventable!=null) { if(eventables==null) eventables = new ArrayList<>(); eventables.add(eventable); for(final Interactor interactor : interactors) interactor.addEventable(eventable); } } @Override public void clearEvents() { for(final T interactor : interactors) interactor.clearEvents(); } @Override public boolean isActivated() { return activated; } @Override public void setActivated(final boolean activated) { this.activated = activated; if(activated && !hasInteractors()) try{ initialiseInteractors(); }catch(InstantiationException | IllegalAccessException e) { ErrorCatcher.INSTANCE.reportError(e); } else for(final T interactor : interactors) interactor.setActivated(activated); interimFeedback(); } @Override public void interimFeedback() { // Nothing to do } @Override public void save(final boolean generalPreferences, final String nsURI, final Document document, final Element root) { // Should be overridden. } @Override public void load(final boolean generalPreferences, final String nsURI, final Element meta) { // Should be overridden. } @Override public void setModified(final boolean modified) { this.modified = modified; } @Override public boolean isModified() { return modified; } @Override public void reinit() { // Should be overridden. } @Override public void onUndoableCleared() { // Should be overridden. } @Override public void onUndoableAdded(final Undoable undoable) { // Should be overridden. } @Override public void onUndoableUndo(final Undoable undoable) { // Should be overridden. } @Override public void onUndoableRedo(final Undoable undoable) { // Should be overridden. } @Override public void onActionCancelled(final Action action) { // Should be overridden. } @Override public void onActionAdded(final Action action) { // Should be overridden. } @Override public void onActionAborted(final Action action) { // Should be overridden. } @Override public void onActionExecuted(final Action action) { // Should be overridden. } @Override public void onActionDone(final Action action) { // Should be overridden. } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/instrument/Interactor.java000066400000000000000000000062701301161664300305120ustar00rootroot00000000000000package org.malai.instrument; import org.malai.action.Action; import org.malai.interaction.Eventable; import org.malai.interaction.Interaction; import org.malai.interaction.InteractionHandler; /** * An interface defining the concept of interactor and its related services.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 2014-09-19 * @version 2.0 */ public interface Interactor extends InteractionHandler { /** * Binds the interaction of the interactor to a Eventable object that produces * events used by the interaction. * @param eventable The eventable object that gathers event used by the interaction. * @since 0.2 */ void addEventable(Eventable eventable); /** * Stops the interaction and clears all its events waiting for a process. * @since 0.2 */ void clearEvents(); /** * After being created by method createAction, the action must be initialised * by this method. * @since 0.2 */ void initAction(); /** * Updates the current action. To override. * @since 0.2 */ void updateAction(); /** * @return True if the condition of the interactor is respected. */ boolean isConditionRespected(); /** * @return The interaction. */ Interaction getInteraction(); /** * @return The action in progress or null. */ Action getAction(); /** * @return True if the interactor is activated. */ boolean isActivated(); /** * @return True: if the interactor is currently used. * since 0.2 */ boolean isRunning(); /** * Sometimes the interaction of two different interactors can overlap themselves. It provokes * that the first interaction can stops while the second is blocked in a intermediary state. * Two solutions are possible to avoid such a problem:
* - the use of this function that perform some tests. If the test fails, the starting interaction * is aborted and the resulting action is never created;
* - the modification of one of the interactions to avoid the overlapping. * @return True: if the starting interaction must be aborted so that the action is never created. * @since 0.2 */ boolean isInteractionMustBeAborted(); /** * @return True if the action is executed on each evolution * of the interaction. */ boolean isExecute(); /** * Defines the interim feedback of the interactor. If overridden, the interim * feedback of its instrument should be define too. */ void interimFeedback(); /** * Activates the interactor. * @param activ True: the interactor is activated. Otherwise, it is desactivated. * @since 3.0 */ void setActivated(boolean activ); /** * @return The instrument that contains the interactor. * @since 0.1 */ Instrument getInstrument(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/instrument/InteractorImpl.java000066400000000000000000000170621301161664300313350ustar00rootroot00000000000000package org.malai.instrument; import org.malai.action.Action; import org.malai.action.ActionsRegistry; import org.malai.error.ErrorCatcher; import org.malai.interaction.Eventable; import org.malai.interaction.Interaction; import org.malai.stateMachine.MustAbortStateMachineException; import org.malai.undo.Undoable; /** * In the Malai interaction model, an instrument links interactions to actions. * Thus, an instrument is composed of Link definitions: each interactor links an interaction * to an action. A Link manages the life cycle of an action following the life cycle * of the interaction (started, aborted, etc.).
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/10/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the action that will produce this interactor. * @param The type of the interaction that will use this interactor. * @param The type of the instrument that will contain this interactor. */ public abstract class InteractorImpl implements Interactor { /** The source interaction. */ protected final I interaction; /** The target action. */ protected A action; /** The instrument that contains the interactor. */ protected final N instrument; /** Specifies if the action must be execute or update * on each evolution of the interaction. */ protected boolean execute; protected final Class clazzAction; /** * Creates a interactor. This constructor must initialise the interaction. The interactor is (de-)activated if the given * instrument is (de-)activated. * @param ins The instrument that contains the interactor. * @param exec Specifies if the action must be execute or update on each evolution of the interaction. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param clazzInteraction The type of the interaction that will be created. Used to instantiate the interaction by reflexivity. * The class must be public and must have a constructor with no parameter. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. * @since 0.2 */ public InteractorImpl(final N ins, final boolean exec, final Class clazzAction, final Class clazzInteraction) throws InstantiationException, IllegalAccessException { super(); if(ins==null || clazzAction==null || clazzInteraction==null) throw new IllegalArgumentException(); this.clazzAction = clazzAction; interaction = clazzInteraction.newInstance(); action = null; instrument = ins; execute = exec; interaction.addHandler(this); setActivated(ins.isActivated()); } @Override public void addEventable(final Eventable eventable) { if(eventable!=null && interaction!=null) interaction.linkToEventable(eventable); } @Override public void clearEvents() { interaction.clearEvents(); } /** * Initialises the action of the interactor. If the attribute 'action' is * not null, nothing will be done. * @since 0.2 */ protected void createAction() { try{ action = clazzAction.newInstance(); }catch(final IllegalAccessException | InstantiationException e){ ErrorCatcher.INSTANCE.reportError(e); } } @Override public abstract void initAction(); @Override public void updateAction() { // to override. } @Override public abstract boolean isConditionRespected(); @Override public I getInteraction() { return interaction; } @Override public A getAction() { return action; } @Override public boolean isActivated() { return instrument.isActivated(); } // /** // * Indicates if the interactor can be run. To be run, no interactor, of the instrument, that produces the // * same type of action must be running. // * @return True: The interactor can be run. // */ // public boolean isRunnable() { // for(final Link link : instrument.links) // if(link!=this && link.isRunning() && link.clazzAction==clazzAction) { // System.out.println("Not RUNNABLE: " + this + " because of " + link); // return true; // // return false; // } // // return true; // } @Override public boolean isRunning() { return interaction.isRunning(); } @Override public boolean isInteractionMustBeAborted() { return false; } @Override public void interactionAborts(final Interaction inter) { if(action!=null && inter==interaction) { action.abort(); // The instrument is notified about the aborting of the action. instrument.onActionAborted(action); if(isExecute()) if(action instanceof Undoable) ((Undoable)action).undo(); else throw new MustBeUndoableActionException(action.getClass()); action = null; instrument.interimFeedback(); } } @Override public void interactionStarts(final Interaction inter) throws MustAbortStateMachineException { if(inter==interaction && isInteractionMustBeAborted()) throw new MustAbortStateMachineException(); //isRunnable() && if(action==null && inter==interaction && isActivated() && isConditionRespected()) { createAction(); initAction(); interimFeedback(); } } @Override public void interactionStops(final Interaction inter) { if(interaction==inter) if(isConditionRespected()) { if(action==null) { createAction(); initAction(); } if(!execute) updateAction(); if(action.doIt()) { instrument.onActionExecuted(action); action.done(); instrument.onActionDone(action); } executeAction(action); action = null; instrument.interimFeedback(); } else if(action!=null) { action.abort(); instrument.onActionAborted(action); action = null; instrument.interimFeedback(); } } private void executeAction(final Action act) { if(act.doIt()) { instrument.onActionExecuted(act); act.done(); instrument.onActionDone(act); } if(act.hadEffect()) { if(act.isRegisterable()) { ActionsRegistry.INSTANCE.addAction(act, instrument); instrument.onActionAdded(act); } else { ActionsRegistry.INSTANCE.cancelActions(act); instrument.onActionCancelled(act); } for(final Action followAction : act.followingActions()) executeAction(followAction); } } @Override public void interactionUpdates(final Interaction inter) { if(inter==interaction && isConditionRespected()) { if(action==null) { createAction(); initAction(); } updateAction(); if(execute && action.canDo()) { action.doIt(); instrument.onActionExecuted(action); } interimFeedback(); } } @Override public boolean isExecute() { return execute; } @Override public void interimFeedback() { // } @Override public void setActivated(final boolean activ) { interaction.setActivated(activ); } @Override public N getInstrument() { return instrument; } } MustBeUndoableActionException.java000066400000000000000000000025601301161664300342050ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/instrumentpackage org.malai.instrument; /** * This exception must be launched when an action which is not undoable want to be undone or redone.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* * @author Arnaud BLOUIN * @date 05/24/10 * @since 0.1 * @version 0.2 */ public class MustBeUndoableActionException extends RuntimeException { private static final long serialVersionUID = 1L; /** The class of the action that want to be undone/redone. */ protected final Class clazz; /** * The default constructor of the exception. * @param clazz The class of the action that want to be undone/redone. * @since 0.1 */ public MustBeUndoableActionException(final Class clazz) { super(); this.clazz = clazz; } @Override public String toString() { return super.toString() + (clazz==null ? "" : " " + clazz.getSimpleName()); //$NON-NLS-1$ //$NON-NLS-2$ } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/000077500000000000000000000000001301161664300256375ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/AbortingState.java000066400000000000000000000017761301161664300312630ustar00rootroot00000000000000package org.malai.interaction; import org.malai.stateMachine.TargetableState; /** * This state defines a aborting state that aborts the interaction.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/19/2010
* @author Arnaud BLOUIN * @since 0.1 */ public class AbortingState extends StateImpl implements TargetableState { /** * @see StateImpl#State(String) */ public AbortingState(final String name) { super(name); } @Override public void onIngoing() { stateMachine.onAborting(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/BasicEventManager.java000066400000000000000000000025751301161664300320310ustar00rootroot00000000000000package org.malai.interaction; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; /** * A basic event manager that gathers events produces by widgets and transfers them to handlers.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2013-02-26
* @author Arnaud BLOUIN * @since 0.2 */ public abstract class BasicEventManager implements EventManager { /** The handlers that are notified when events occur. */ protected final List handlers; /** * Creates a event manager that gathers events and transfers them to handlers. * @since 0.2 */ public BasicEventManager() { super(); handlers = new CopyOnWriteArrayList<>(); } @Override public void addHandlers(final EventProcessor h) { if(h!=null) handlers.add(h); } @Override public void removeHandler(final EventProcessor h) { if(h!=null) handlers.remove(h); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/EventManager.java000066400000000000000000000030361301161664300310600ustar00rootroot00000000000000package org.malai.interaction; /** * This interface is the base interface of object that want to manager events produced by, for example, * Swing, Android.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2013-02-21
* @author Arnaud BLOUIN * @since 0.2 * @ The root type of the component to support. For instance with Swing the root component is Component, for Android it is View. */ public interface EventManager { /** * Detaches the EventManager to the listened component. * @param comp The Component to detach. */ void detachForm(final T comp); /** * Attaches the EventManager to the given component to listen. * @param comp The Component to listen. */ void attachTo(final T comp); /** * Adds a handler to the event manager. * @param h The handler to add. Must not be null. * @since 0.1 */ void addHandlers(final EventProcessor h); /** * Removes a handler from the event manager. * @param h The handler to remove. Must not be null. * @since 0.1 */ void removeHandler(final EventProcessor h); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/EventProcessor.java000066400000000000000000000017651301161664300314740ustar00rootroot00000000000000package org.malai.interaction; /** * This interface can be used for object that want to gather events (mouse pressed, etc.) produced by HIDs.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/19/2010
* @author Arnaud BLOUIN * @since 0.1 */ public interface EventProcessor { /** * Defines action to do when a timeout is elapsed. * @param timeoutTransition The transition which produced the timeout event. * @since 0.2 */ void onTimeout(final TimeoutTransition timeoutTransition); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/Eventable.java000066400000000000000000000020471301161664300304120ustar00rootroot00000000000000package org.malai.interaction; /** * This interface corresponds to objects that may have an event manager.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/13/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface Eventable { /** * @return True: the Eventable object has an event manager that gathers events it produces. * @since 0.2 */ boolean hasEventManager(); /** * @return The event manager that gathers events the Eventable object produces. * @since 0.2 */ EventManager getEventManager(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/InitState.java000066400000000000000000000021461301161664300304110ustar00rootroot00000000000000package org.malai.interaction; import org.malai.stateMachine.MustAbortStateMachineException; import org.malai.stateMachine.SourceableState; /** * This state defines a initial state that starts the interaction.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/19/2010
* @author Arnaud BLOUIN * @since 0.1 */ public class InitState extends StateImpl implements SourceableState { /** * Creates the initial state. * @since 0.1 */ public InitState() { super("Init"); //$NON-NLS-1$ } @Override public void onOutgoing() throws MustAbortStateMachineException { stateMachine.onStarting(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/Interaction.java000066400000000000000000000044041301161664300307630ustar00rootroot00000000000000package org.malai.interaction; import java.util.List; import org.malai.stateMachine.State; import org.malai.stateMachine.StateMachine; import org.malai.stateMachine.MustAbortStateMachineException; /** * An interface defining the concept of interaction and its related services.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 2014-09-19 * @version 2.0 */ public interface Interaction extends StateMachine, EventProcessor { @Override void setActivated(boolean activated); @Override void reinit(); /** * @return The handlers that listens to the interaction. */ List getHandlers(); /** * Adds an interaction handler. * @param handler The handler to add. * @since 0.1 */ void addHandler(InteractionHandler handler); @Override void addState(State state); /** * Links the interaction to an eventable object (e.g. a MPanel or a MButton). * @param eventable The Eventable object. * @since 0.2 */ void linkToEventable(Eventable eventable); @Override boolean isRunning(); @Override void onUpdating() throws MustAbortStateMachineException; /** * @return The ID of last HID that has been used by the interaction. If the interaction has stopped or is * aborted, the value of the attribute is -1. * @since 0.2 */ int getLastHIDUsed(); /** * @param hid The ID of last HID that has been used by the interaction. If the interaction has stopped or is * aborted, the value of the attribute is -1. * @since 0.2 */ void setLastHIDUsed(int hid); /** * Clears the events of the interaction still in process. * @since 0.2 */ void clearEventsStillInProcess(); /** * Stops the interaction and clears all its events waiting for a process. * @since 0.2 */ void clearEvents(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/InteractionHandler.java000066400000000000000000000036661301161664300322720ustar00rootroot00000000000000package org.malai.interaction; import org.malai.stateMachine.MustAbortStateMachineException; /** * Defines an interaction for objects that want to by notified when the state of an interaction changed.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 10/10/2009
* @author Arnaud BLOUIN * @since 0.1 */ public interface InteractionHandler { /** * Happens when the interaction quits its initial state. * @param interaction The concerned interaction. * @throws MustAbortStateMachineException If the interaction must be aborted. * @since 0.1 */ void interactionStarts(final Interaction interaction) throws MustAbortStateMachineException; /** * Happens when the interaction goes to standard state. * @param interaction The concerned interaction. * @throws MustAbortStateMachineException If the interaction must be aborted. * @since 0.1 */ void interactionUpdates(final Interaction interaction) throws MustAbortStateMachineException; /** * Happens when the interaction goes to a terminal state. * @param interaction The concerned interaction. * @throws MustAbortStateMachineException If the interaction must be aborted. * @since 0.1 */ void interactionStops(final Interaction interaction) throws MustAbortStateMachineException; /** * Happens when the interaction goes to an aborting state. * @param interaction The concerned interaction. * @since 0.1 */ void interactionAborts(final Interaction interaction); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/InteractionImpl.java000066400000000000000000000254431301161664300316130ustar00rootroot00000000000000package org.malai.interaction; import java.util.ArrayList; import java.util.List; import org.malai.picking.Pickable; import org.malai.picking.Picker; import org.malai.stateMachine.State; import org.malai.stateMachine.Transition; import org.malai.stateMachine.MustAbortStateMachineException; /** * Defines an interaction as defined in the Malai model.
* An interaction is a state machine and a class.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 10/10/2009
* @author Arnaud BLOUIN * @since 0.1 */ public abstract class InteractionImpl implements Interaction { /** The states that compose the finite state machine. */ protected final List states; /** The initial state the starts the state machine. */ protected final InitState initState; /** The current state of the state machine when the state machine is executed. */ protected State currentState; /** Defines if the interaction is activated or not. If not, the interaction will not * change on events. * */ protected boolean activated; /** The handlers that want to be notified when the state machine of the * interaction changed. */ protected List handlers; /** The events still in process. For example when the user press key ctrl and scroll one * time using the wheel of the mouse, the interaction scrolling is finished but the event keyPressed * 'ctrl' is still in process. At the end of the interaction, these events are re-introduced into the * state machine of the interaction for processing. */ protected List stillProcessingEvents; /** The current timeout in progress. */ protected TimeoutTransition currentTimeout; /** Defines the ID of last HID that has been used by the interaction. If the interaction has stopped or is * aborted, the value of the attribute is -1. */ protected int lastHIDUsed; /** * Creates the interaction with a init state. */ public InteractionImpl() { this(new InitState()); } /** * Creates the state machine. * @param initState The initial state of the state machine. * @throws IllegalArgumentException If the given state is null. * @since 0.1 */ public InteractionImpl(final InitState initState) { super(); if(initState==null) throw new IllegalArgumentException(); currentTimeout = null; activated = true; states = new ArrayList<>(); initState.stateMachine = this; this.initState = initState; addState(initState); reinit(); } /** * Initialises the interaction: creates the states and the transitions. * @since 0.1 */ protected abstract void initStateMachine(); @Override public void setActivated(final boolean activated) { this.activated = activated; if(!activated) { reinit(); clearEventsStillInProcess(); } } @Override public boolean isActivated() { return activated; } @Override public State getCurrentState() { return currentState; } @Override public void reinit() { if(currentTimeout!=null) currentTimeout.stopTimeout(); currentTimeout = null; currentState = initState; lastHIDUsed = -1; } @Override public List getHandlers() { return handlers; } @Override public void addHandler(final InteractionHandler handler) { if(handler!=null) { if(handlers==null) handlers = new ArrayList<>(); handlers.add(handler); } } /** * Notifies handlers that the interaction starts. * @since 0.1 */ protected void notifyHandlersOnStart() throws MustAbortStateMachineException { try { if(handlers!=null) for(final InteractionHandler handler : handlers) handler.interactionStarts(this); }catch(final MustAbortStateMachineException ex) { notifyHandlersOnAborting(); throw ex; } } /** * Notifies handlers that the interaction updates. * @since 0.1 */ protected void notifyHandlersOnUpdate() throws MustAbortStateMachineException { try { if(handlers!=null) for(final InteractionHandler handler : handlers) handler.interactionUpdates(this); }catch(final MustAbortStateMachineException ex) { notifyHandlersOnAborting(); throw ex; } } /** * Notifies handlers that the interaction stops. * @since 0.1 */ protected void notifyHandlersOnStop() throws MustAbortStateMachineException { try { if(handlers!=null) for(final InteractionHandler handler : handlers) handler.interactionStops(this); }catch(final MustAbortStateMachineException ex) { notifyHandlersOnAborting(); throw ex; } } /** * Notifies handlers that the interaction stops. * @since 0.1 */ protected void notifyHandlersOnAborting() { if(handlers!=null) for(final InteractionHandler handler : handlers) handler.interactionAborts(this); } /** * Try to find a Pickable object at the given coordinate in the given source object. * @param x The X-coordinate of the location to check. * @param y The Y-coordinate of the location to check. * @param source The source object in which the function will search. * @return null if nothing is found. Otherwise a pickable object. * @since 0.2 */ public static Pickable getPickableAt(final double x, final double y, final Object source) { if(source==null) return null; if(source instanceof Picker) return ((Picker)source).getPickableAt(x, y); if(source instanceof Pickable) { final Pickable srcPickable = (Pickable) source; if(srcPickable.contains(x, y)) return srcPickable; return srcPickable.getPicker().getPickableAt(x, y); } return null; } @Override public void addState(final State state) { if(state!=null) { states.add(state); state.setStateMachine(this); } } @Override public void linkToEventable(final Eventable eventable) { if(eventable!=null && eventable.hasEventManager()) eventable.getEventManager().addHandlers(this); } @Override public boolean isRunning() { return activated && currentState!=initState; } /** * Executes the given transition. Only if the state machine is activated. * @param transition The transition to execute. * @since 0.1 */ protected void executeTransition(final Transition transition) { if(activated) try { if(transition!=null) { transition.action(); transition.getInputState().onOutgoing(); currentState = transition.getOutputState(); transition.getOutputState().onIngoing(); } }catch(final MustAbortStateMachineException ex) { reinit(); } } /** * Stops the current timeout transition. * @since 0.2 */ protected void stopCurrentTimeout() { if(currentTimeout!=null) { currentTimeout.stopTimeout(); currentTimeout = null; } } @Override public boolean checkTransition(final Transition transition) { final boolean ok; if(transition.isGuardRespected()) { stopCurrentTimeout(); executeTransition(transition); ok = true; } else ok = false; return ok; } @Override public void onTimeout(final TimeoutTransition timeoutTransition) { if(!activated || timeoutTransition==null) return ; executeTransition(timeoutTransition); } /** * At the end of the interaction, the events still in process must be recycled * to be reused in the interaction. For instance will the KeysScrolling interaction, * if key 'ctrl' is pressed and the user scrolls the key event 'ctrl' is re-introduced * into the state machine of the interaction to be processed. * @since 0.2 */ protected void processEvents() { if(stillProcessingEvents!=null) synchronized(stillProcessingEvents) { Event event; // All the events must be processed but the list stillProcessingEvents can be modified // during the process. So, a clone of the list must be created. final List list = new ArrayList<>(stillProcessingEvents); // All the events must be processed. while(!list.isEmpty()) { event = list.remove(0); // Do not forget to remove the event from its original list. stillProcessingEvents.remove(0); processEvent(event); } } } /** * At the end of the interaction, the events still in process must be recycled * to be reused in the interaction. For instance will the KeysScrolling interaction, * if key 'ctrl' is pressed and the user scrolls the key event 'ctrl' is re-introduced * into the state machine of the interaction to be processed. * Companion operation of processEvents. Must be implemented by the different GUI libraries. */ protected abstract void processEvent(final Event event); @Override public void onTerminating() throws MustAbortStateMachineException { notifyHandlersOnStop(); reinit(); processEvents(); } @Override public void onAborting() { notifyHandlersOnAborting(); reinit(); // When an interaction is aborted, the events in progress must not be reused. clearEventsStillInProcess(); } @Override public void onStarting() throws MustAbortStateMachineException { notifyHandlersOnStart(); checkTimeoutTransition(); } @Override public void onUpdating() throws MustAbortStateMachineException { notifyHandlersOnUpdate(); checkTimeoutTransition(); } /** * Checks if the current state has a timeout transition. If it is the case, * the timeout transition is launched. * @since 0.2 */ protected void checkTimeoutTransition() { boolean again = true; Transition transition; for(int i=0, j=currentState.getTransitions().size(); i *
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/19/2010
* @author Arnaud BLOUIN * @since 0.1 */ public class IntermediaryState extends StateImpl implements SourceableState, TargetableState { /** * @see StateImpl#State(String) */ public IntermediaryState(final String name) { super(name); } @Override public void onIngoing() throws MustAbortStateMachineException { stateMachine.onUpdating(); } @Override public void onOutgoing() throws MustAbortStateMachineException { // } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/StateImpl.java000066400000000000000000000046151301161664300304120ustar00rootroot00000000000000package org.malai.interaction; import java.util.ArrayList; import java.util.List; import org.malai.stateMachine.State; import org.malai.stateMachine.StateMachine; import org.malai.stateMachine.Transition; /** * A state is a component of a state machine.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 10/10/2010
* @author Arnaud BLOUIN * @since 0.1 */ public abstract class StateImpl implements State { /** The name of the state. */ protected final String name; /** The list of the transitions that leave the state. */ protected final List transitions; /** The state machine that contains the state. */ protected Interaction stateMachine; /** * Creates the state. * @param name The name of the state. * @throws IllegalArgumentException If the given name is null. * @since 0.1 */ public StateImpl(final String name) { super(); if(name==null) throw new IllegalArgumentException(); this.name = name; stateMachine = null; transitions = new ArrayList<>(); } @Override public void setStateMachine(final StateMachine sm) { if(sm instanceof Interaction) stateMachine = (Interaction)sm; } @Override public Interaction getStateMachine() { return stateMachine; } @Override public void addTransition(final Transition trans) { if(trans!=null) transitions.add(trans); } @Override public String getName() { return name; } @Override public List getTransitions() { return transitions; } @Override public Transition getTransition(final int i) { return i<0 || i>=transitions.size() ? null : transitions.get(i); } @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(getClass().getCanonicalName()).append('[').append(name).append(',').append(' '); for(final Transition t : transitions) sb.append(t).append(',').append(' '); sb.append(']'); return sb.toString(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/TerminalState.java000066400000000000000000000021431301161664300312560ustar00rootroot00000000000000package org.malai.interaction; import org.malai.stateMachine.MustAbortStateMachineException; import org.malai.stateMachine.TargetableState; /** * This state defines a terminal state that ends the interaction.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/19/2010
* @author Arnaud BLOUIN * @since 0.1 */ public class TerminalState extends StateImpl implements TargetableState { /** * @see StateImpl#State(String) */ public TerminalState(final String name) { super(name); } @Override public void onIngoing() throws MustAbortStateMachineException { stateMachine.onTerminating(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/TimeoutTransition.java000066400000000000000000000057571301161664300322210ustar00rootroot00000000000000package org.malai.interaction; import org.malai.stateMachine.StateMachine; import org.malai.stateMachine.SourceableState; import org.malai.stateMachine.TargetableState; /** * This transition defines a timeout: when the user does nothing during a given duration, * the timeout transition is executed.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 11/01/2011
* @author Arnaud BLOUIN * @since 0.2 */ public class TimeoutTransition extends TransitionImpl { /** The timeout in ms. */ protected int timeout; /** The current thread in progress. */ private Thread timeoutThread; /** * Creates the transition. * @param inputState The source state of the transition. * @param outputState The target state of the transition. * @param timeout The timeout in ms. Must be greater than 0. * @throws IllegalArgumentException If one of the given parameters is null or not valid. * @since 0.2 */ public TimeoutTransition(final SourceableState inputState, final TargetableState outputState, final int timeout) { super(inputState, outputState); if(timeout<=0) throw new IllegalArgumentException(); this.timeout = timeout; } /** * Launches the chronometre (and its thread). * @since 0.2 */ public void startTimeout() { if(timeoutThread==null) { timeoutThread = new Thread(new TimeoutRunnable()); timeoutThread.start(); } } /** * Stops the chronometre (and its thread). * @since 0.2 */ public void stopTimeout() { if(timeoutThread!=null) { timeoutThread.interrupt(); timeoutThread = null; } } /** * @param timeout The timeout in ms. Must be greater than 0. * @since 0.2 */ public void setTimeout(final int timeout) { if(timeout>0) this.timeout = timeout; } /** * @return The timeout in ms. * @since 0.2 */ public int getTimeout() { return timeout; } /** * A TimeoutRunnable defines the executable part of the thread which is * thrown when the chronometre of the transition is launched. */ class TimeoutRunnable implements Runnable { @Override public void run() { try{ // Sleeping the thread. Thread.sleep(TimeoutTransition.this.timeout); // There is a timeout and the interaction must be notified of that. final StateMachine sm = TimeoutTransition.this.getInputState().getStateMachine(); // Notifying the interaction of the timeout. if(sm instanceof Interaction) ((Interaction)sm).onTimeout(TimeoutTransition.this); }catch(final InterruptedException ex){ // OK, thread stopped. } } } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/TransitionImpl.java000066400000000000000000000044311301161664300314600ustar00rootroot00000000000000package org.malai.interaction; import org.malai.stateMachine.Transition; import org.malai.stateMachine.SourceableState; import org.malai.stateMachine.TargetableState; /** * A transition links two states of a state machine if a given condition is respected. * Actions can be performed when executing the transition.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 06/01/2010
* @author Arnaud BLOUIN * @since 0.1 */ public abstract class TransitionImpl implements Transition { /** The source state. */ protected final SourceableState inputState; /** The target state. */ protected final TargetableState outputState; /** The ID of the HID that produced the transition. */ protected int hid; /** * Defines a transition. * @param inputState The source state of the transition. * @param outputState The target state of the transition. * @throws IllegalArgumentException If one of the given parameters is null or not valid. * @since 0.1 */ public TransitionImpl(final SourceableState inputState, final TargetableState outputState) { if(inputState==null || outputState==null) throw new IllegalArgumentException(); this.inputState = inputState; this.outputState = outputState; this.inputState.addTransition(this); } @Override public void action() { // } @Override public boolean isGuardRespected() { return true; } @Override public SourceableState getInputState() { return inputState; } @Override public TargetableState getOutputState() { return outputState; } @Override public String toString() { return getClass().getSimpleName() + '[' + inputState.getName() + ">>" + outputState.getName() + ']'; //$NON-NLS-1$ } @Override public int getHid() { return hid; } @Override public void setHid(final int hid) { this.hid = hid; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/interaction/WidgetTransition.java000066400000000000000000000025451301161664300320060ustar00rootroot00000000000000package org.malai.interaction; import org.malai.stateMachine.SourceableState; import org.malai.stateMachine.TargetableState; /** * This transition must be used to use a widget within an interaction.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* @author Arnaud BLOUIN */ public abstract class WidgetTransition extends TransitionImpl { /** The pressed button. */ protected T widget; /** * {@link TransitionImpl#Transition(SourceableState, TargetableState)} */ public WidgetTransition(final SourceableState inputState, final TargetableState outputState) { super(inputState, outputState); } /** * @return The widget used. */ public T getWidget() { return widget; } /** * Sets the widget. * @param widget The widget to set. Must not be null. */ public void setWidget(final T widget) { if(widget!=null) this.widget = widget; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/000077500000000000000000000000001301161664300247535ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/ActiveArrayList.java000066400000000000000000000071131301161664300306660ustar00rootroot00000000000000package org.malai.mapping; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * Defines an active list that when an element is added/removed, then mapping registry * is then notified.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/15/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the elements contained in the list. */ public class ActiveArrayList extends ArrayList implements IActiveList { private static final long serialVersionUID = 1L; /** * {@link ArrayList#ArrayList()} */ public ActiveArrayList() { super(); } /** * {@link ArrayList#ArrayList(int)} */ public ActiveArrayList(final int initialCapacity) { super(initialCapacity); } /** * {@link ArrayList#ArrayList(Collection)} * @param coll The collection which elements will be added the the list. */ public ActiveArrayList(final Collection coll) { super(coll); } @Override public void move(final int srcIndex, final int targetIndex) { if(srcIndex<0 || targetIndex<0 || srcIndex>=size() || targetIndex>size()) throw new IndexOutOfBoundsException(); if(srcIndex==targetIndex) return ; final E elt = super.remove(srcIndex); if(targetIndex==size()) super.add(elt); else super.add(targetIndex, elt); MappingRegistry.REGISTRY.onObjectMoved(this, elt, srcIndex, targetIndex); } @Override public boolean add(final E element) { final boolean ok = super.add(element); if(ok) MappingRegistry.REGISTRY.onObjectAdded(this, element, -1); return ok; } @Override public void add(final int index, final E element) { super.add(index, element); MappingRegistry.REGISTRY.onObjectAdded(this, element, index); } @Override public boolean addAll(final Collection collection) { final boolean ok = super.addAll(collection); if(ok) for(final E obj : collection) MappingRegistry.REGISTRY.onObjectAdded(this, obj, -1); return ok; } @Override public boolean addAll(final int index, final Collection collection) { final boolean ok = super.addAll(index, collection); if(ok) { final List array = new ArrayList<>(collection); int i = array.size()-1; while(i>=0) { MappingRegistry.REGISTRY.onObjectAdded(this, array.get(i), index); i--; } } return ok; } @Override public void clear() { MappingRegistry.REGISTRY.onListCleaned(this); super.clear(); } @Override public E remove(final int index) { final E elt = super.remove(index); if(elt!=null) MappingRegistry.REGISTRY.onObjectRemoved(this, elt, index); return elt; } @Override public boolean remove(final Object obj) { final int index = indexOf(obj); if(index==-1) return false; super.remove(index); MappingRegistry.REGISTRY.onObjectRemoved(this, obj, index); return true; } @Override public E set(final int index, final E element) { final E elt = get(index); super.set(index, element); MappingRegistry.REGISTRY.onObjectRemoved(this, elt, index); MappingRegistry.REGISTRY.onObjectAdded(this, element, index); return elt; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/ActiveUnary.java000066400000000000000000000030531301161664300300510ustar00rootroot00000000000000package org.malai.mapping; /** * An active unary relation is an object that may contain a value (cardinalities 0..1). When the value is modified, * the mapping registry is notified and the corresponding mappings executed.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/16/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the element contained by the active 0-1 relation. */ public class ActiveUnary implements IUnary { /** The value of the singleton. */ protected T value; /** * Creates an empty singleton. * @since 0.2 */ public ActiveUnary() { this(null); } /** * Creates a singleton with a given value. * @param value The value of the singleton. * @since 0.2 */ public ActiveUnary(final T value) { super(); this.value = value; } @Override public T getValue() { return value; } @Override public void setValue(final T value) { final T replacedValue = this.value; this.value = value; MappingRegistry.REGISTRY.onObjectReplaced(this, replacedValue); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/IActiveList.java000066400000000000000000000023641301161664300300030ustar00rootroot00000000000000package org.malai.mapping; import java.util.List; /** * This interface completes the List interface with necessary methods.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/15/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the elements contained in the active list. */ public interface IActiveList extends List { /** * Moves the object located at the position srcIndex to the location specified * by the targetIndex. * @param srcIndex The position of the object to move. * @param targetIndex The final position of the moved object. * @throws ArrayIndexOutOfBoundsException if one of the given index is not valid. * @since 0.2 */ void move(final int srcIndex, final int targetIndex); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/IMapping.java000066400000000000000000000064311301161664300273260ustar00rootroot00000000000000package org.malai.mapping; /** * This interface defines the concept of mapping that link source objects with target objects.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/15/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface IMapping { /** * Returns the source object of the mapping. If there is several source objects, a collection is returned. * @return The source object of the mapping. * @since 0.2 */ Object getSource(); /** * Returns the target object of the mapping. If there is several target objects, a collection is returned. * @return The source object of the mapping. * @since 0.2 */ Object getTarget(); /** * Executes the mapping for the addition of an object. * @param list The modified source list. * @param object The added object. * @param index The position where the object has been added. -1 = the last position. * @since 0.2 */ void onObjectAdded(final Object list, final Object object, final int index); /** * Executes the mapping for the deletion of an object. * @param list The modified source list. * @param object The deleted object. * @param index The position where the object has been deleted. -1 = the last position. * @since 0.2 */ void onObjectRemoved(final Object list, final Object object, final int index); /** * Executes the mapping when all the elements of the source were removed. * @param list The list before the cleaning, i.e. it still contains all the elements in * order to know which elements have been removed. * @since 3.0 */ void onListCleaned(final Object list); /** * Executes the mapping for the move of an object. * @param list The modified source list. * @param object The move object. * @param srcIndex The source position of the object. -1 = the last position. * @param targetIndex The target position of the object. -1 = the last position. * @since 0.2 */ void onObjectMoved(final Object list, final Object object, final int srcIndex, final int targetIndex); /** * Executes the mapping when an object has been replaced by an other one. * @param object The singleton that contains the new object. * @param replacedObject The old object contained in the singleton that has been replaced. * @since 0.2 */ void onObjectReplaced(final IUnary object, final Object replacedObject); /** * Executes the mapping for the modification of an object. * @param object The modified object. * @since 0.2 */ void onObjectModified(final Object object); /** * Removes the references of the mapped objects of the mapping to avoid memory leaks. * @since 0.2 */ void clear(); /** * At start, the mapping must be executed one time to initialise the binding between * source and target objects. * @since 3.0 */ void init(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/IMappingRegistry.java000066400000000000000000000110311301161664300310470ustar00rootroot00000000000000package org.malai.mapping; /** * Defines an interface for a registry that gathers modifications made to a listened objects.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/15/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface IMappingRegistry { /** * At start, mappings must be executed one time to initialise the mapping. * @since 0.2 */ void initMappings(); /** * Adds a mapping to the registry. * @param mapping The mapping to add. * @since 0.2 */ void addMapping(final IMapping mapping); /** * Executes mappings related to the given list for the addition of an object. * @param list The modified source list. * @param object The added object. * @param index The position where the object has been added. * @since 0.2 */ void onObjectAdded(final IActiveList list, final T object, final int index); /** * Executes mappings related to the given list for the deletion of an object. * @param list The modified source list. * @param object The deleted object. * @param index The position where the object has been deleted. * @since 0.2 */ void onObjectRemoved(final IActiveList list, final Object object, final int index); /** * Executes the mapping when all the elements of the source were removed. * @param list The list before the cleaning, i.e. it still contains all the elements in * order to know which elements have been removed. * @since 3.0 */ void onListCleaned(final Object list); /** * Executes mappings related to the given list for the move of an object. * @param list The modified source list. * @param object The move object. * @param srcIndex The source position of the object. * @param targetIndex The target position of the object. * @since 0.2 */ void onObjectMoved(final IActiveList list, final T object, final int srcIndex, final int targetIndex); /** * Executes mappings related to the given list for the modification of an object. * @param object The modified object. * @since 0.2 */ void onObjectModified(final Object object); /** * Executes the mapping when an object has been replaced by an other one. * @param object The singleton that contains the new object. * @param replacedObject The old object contained in the singleton that has been replaced. * @since 0.2 */ void onObjectReplaced(final IUnary object, final T replacedObject); /** * Removes the mappings that use the given object as source. * @param source A source object of the mappings to remove. * @since 0.2 */ void removeMappingsUsingSource(final Object source); /** * Removes the mappings that use the given object as target. * @param target A target object of the mappings to remove. * @param clazz The type of the mappings to remove. * @since 0.2 */ void removeMappingsUsingTarget(final Object target, final Class clazz); /** * Removes the mappings that use the given object as target. * @param target A target object of the mappings to remove. * @since 0.2 */ void removeMappingsUsingTarget(final Object target); /** * Removes the mappings of the given type that use the given object as source. * @param source A source object of the mappings to remove. * @param clazz The type of the mappings to remove. * @since 0.2 */ void removeMappingsUsingSource(final Object source, final Class clazz); /** * @param source The source object used to find the target object matching the given class. * @param targetType The class of the target object to find. * @return The target object found using the given source object, or null. * @since 0.2 */ T getTargetFromSource(final Object source, final Class targetType); /** * @param target The target object used to find the source object matching the given class. * @param sourceType The class of the source object to find. * @return The source object found using the given target object, or null. * @since 0.2 */ T getSourceFromTarget(final Object target, final Class sourceType); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/IUnary.java000066400000000000000000000020761301161664300270320ustar00rootroot00000000000000package org.malai.mapping; /** * This interface defines methods for an unary relation that may contain a value of type T (cardinality 0..1).
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/16/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the element contained by the 0-1 relation. */ public interface IUnary { /** * @return The value of the singleton. * @since 0.2 */ T getValue(); /** * Sets a new value to the singleton. * @param value The new value. * @since 0.2 */ void setValue(final T value); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/List2ListMapping.java000066400000000000000000000023721301161664300307670ustar00rootroot00000000000000package org.malai.mapping; import java.util.List; /** * Defines a mapping established between two lists.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/15/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the source element of the mapping. * @param The type of the target element of the mapping. */ public abstract class List2ListMapping extends List2ObjectMapping> { /** * Creates the mapping. * @param source The source list. * @param target The target list. * @throws IllegalArgumentException If one of the given lists is null or if they are the same object. * @since 0.2 */ public List2ListMapping(final List source, final List target) { super(source, target); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/List2ObjectMapping.java000066400000000000000000000032651301161664300312640ustar00rootroot00000000000000package org.malai.mapping; import java.util.List; /** * Defines a mapping established between a list and an object.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 01/19/2012
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the source element, contained in a list, of the mapping. * @param The type of the target element of the mapping. */ public abstract class List2ObjectMapping implements IMapping { /** The source list. */ protected List source; /** The target object. */ protected F target; /** * Creates the mapping. * @param source The source list. * @param target The target object. * @throws IllegalArgumentException If one of the given elements is null or if they are the same object. * @since 0.2 */ public List2ObjectMapping(final List source, final F target) { super(); if(source==null || target==null || source==target) throw new IllegalArgumentException(); this.source = source; this.target = target; } @Override public List getSource() { return source; } @Override public F getTarget() { return target; } @Override public void clear() { source = null; target = null; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/MappingRegistry.java000066400000000000000000000320141301161664300307420ustar00rootroot00000000000000package org.malai.mapping; import java.util.ArrayList; import java.util.Collection; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; /** * This registry allows to map source objects to target objects using mappings. * When a source object is modified, its corresponding mappings are executed to * update the corresponding target objects.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/15/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public final class MappingRegistry implements IMappingRegistry { /** The singleton of the class. */ public static final IMappingRegistry REGISTRY = new MappingRegistry(); /** Contains objects and their unique mapping. */ private final Map uniqueMappings; /** * Contains objects and their mappings. The difference with uniqueMappings is that * multiMappings is not used by default (i.e. when only one mapping is attributed to an object) * to save memory. */ private final Map> multiMappings; private final Map invertedUniqueMappings; private final Map> invertedMultiMappings; /** * Creates a mapping registry. * @since 0.2 */ private MappingRegistry() { super(); uniqueMappings = new IdentityHashMap<>(); multiMappings = new IdentityHashMap<>(); invertedUniqueMappings = new IdentityHashMap<>(); invertedMultiMappings = new IdentityHashMap<>(); } @Override public void initMappings() { final Collection coll = uniqueMappings.values(); for(final IMapping mapping : coll) mapping.init(); final Collection> collList = multiMappings.values(); for(final List list : collList) for(final IMapping mapping : list) mapping.init(); } @Override public T getTargetFromSource(final Object source, final Class targetType) { return getSrcOrTarFromTarOrSrc(true, source, targetType); } @Override public T getSourceFromTarget(final Object target, final Class sourceType) { return getSrcOrTarFromTarOrSrc(false, target, sourceType); } /** * Allows to get the source or the target object of a mapping using the target or the source object. * @param fromSource True: the target object while be searched. Otherwise, the source object. * @param object The source or target object of the mapping used to get the target or source object. * @param type The class of the object to return. * @return The found object or null. * @since 0.2 */ public T getSrcOrTarFromTarOrSrc(final boolean fromSource, final Object object, final Class type) { final List mappings = fromSource ? getMappingFromSource(object) : getMappingFromTarget(object); T result = null; switch(mappings.size()) { case 0: break; case 1: Object obj = fromSource ? mappings.get(0).getTarget() : mappings.get(0).getSource(); // We must check that the type of the mapping corresponds to the given type. result = type.isInstance(obj) ? type.cast(obj) : null; break; default: final int size = mappings.size(); int i = 0; while(result==null && i getMappingFromSource(final Object source) { return getMapping(source, uniqueMappings, multiMappings); } /** * @param target This object is used to find the mapping that uses is as a target object. * @return The found mapping or null. * @since 0.2 */ public List getMappingFromTarget(final Object target) { return getMapping(target, invertedUniqueMappings, invertedMultiMappings); } private static List getMapping(final Object object, final Map uniqueMap, final Map> multiMap) { final List mappings = new ArrayList<>(); if(object!=null) { final IMapping mapping = uniqueMap.get(object); if(mapping==null) { final List multi = multiMap.get(object); if(multi!=null) for(final IMapping map : multi) mappings.add(map); }else mappings.add(mapping); } return mappings; } @Override public void addMapping(final IMapping mapping) { if(mapping==null) return ; //TODO manage mappings with several sources or targets. addMappings(mapping, mapping.getSource(), uniqueMappings, multiMappings); addMappings(mapping, mapping.getTarget(), invertedUniqueMappings, invertedMultiMappings); } /** * Is used by method addMapping(mapping). * @param mapping The mapping to add. * @param object The object that will be used as key in the map. * @param uniqueMap The map that contains unique mappings. * @param multiMap The map that contains multiple mappings. * @since 0.2 */ private static void addMappings(final IMapping mapping, final Object object, final Map uniqueMap, final Map> multiMap) { final List mappings = multiMap.get(object); if(mappings!=null) mappings.add(mapping); else if(uniqueMap.get(object)==null) uniqueMap.put(object, mapping); else { final List list = new ArrayList<>(); list.add(uniqueMap.remove(object)); list.add(mapping); multiMap.put(object, list); } } @Override public void onObjectAdded(final IActiveList list, final T object, final int index) { final IMapping mapping = uniqueMappings.get(list); if(mapping==null) { final List mappings = multiMappings.get(list); if(mappings!=null) for(final IMapping map : mappings) map.onObjectAdded(list, object, index); } else mapping.onObjectAdded(list, object, index); } @Override public void onObjectRemoved(final IActiveList list, final Object object, final int index) { final IMapping mapping = uniqueMappings.get(list); if(mapping==null) { final List mappings = multiMappings.get(list); if(mappings!=null) for(final IMapping map : mappings) map.onObjectRemoved(list, object, index); } else mapping.onObjectRemoved(list, object, index); } @Override public void onListCleaned(final Object list) { final IMapping mapping = uniqueMappings.get(list); if(mapping==null) { final List mappings = multiMappings.get(list); if(mappings!=null) for(final IMapping map : mappings) map.onListCleaned(list); } else mapping.onListCleaned(list); } @Override public void onObjectMoved(final IActiveList list, final T object, final int srcIndex, final int targetIndex) { final IMapping mapping = uniqueMappings.get(list); if(mapping==null) { final List mappings = multiMappings.get(list); if(mappings!=null) for(final IMapping map : mappings) map.onObjectMoved(list, object, srcIndex, targetIndex); } else mapping.onObjectMoved(list, object, srcIndex, targetIndex); } @Override public void onObjectReplaced(final IUnary object, final T replacedObject) { final IMapping mapping = uniqueMappings.get(object); if(mapping==null) { final List mappings = multiMappings.get(object); if(mappings!=null) for(final IMapping map : mappings) map.onObjectReplaced(object, replacedObject); } else mapping.onObjectReplaced(object, replacedObject); } @Override public void onObjectModified(final Object object) { final IMapping mapping = uniqueMappings.get(object); if(mapping==null) { final List mappings = multiMappings.get(object); if(mappings!=null) for(final IMapping map : mappings) map.onObjectModified(object); } else mapping.onObjectModified(object); } @Override public void removeMappingsUsingSource(final Object source, final Class clazz) { removeMappingsUsingSource(source, clazz, true); } /** * Idem than removeMappingsUsingSource. * @param removeTargetMappings True: the inverted hash maps will be cleaned too. * @since 0.2 */ protected void removeMappingsUsingSource(final Object source, final Class clazz, final boolean removeTargetMappings) { removeMappings(source, clazz, uniqueMappings, multiMappings, false, removeTargetMappings); } @Override public void removeMappingsUsingTarget(final Object target, final Class clazz) { removeMappingsUsingTarget(target, clazz, true); } /** * Idem than removeMappingsUsingTarget. * @param removeSourceMappings True: the standard hash maps will be cleaned too. * @since 0.2 */ protected void removeMappingsUsingTarget(final Object target, final Class clazz, final boolean removeSourceMappings) { removeMappings(target, clazz, invertedUniqueMappings, invertedMultiMappings, true, removeSourceMappings); } /** * Remove the mappings of the given type and using the given object from the hash maps. * @param object The source or target object of the mappings to remove. * @param clazz The type of the mappings to remove. * @param uniqueMaps The hash map that contains the unique mappings. * @param multiMaps The hash map that contains the mappings contained into a list. * @param removeUsingTarget True: will remove the mappings by considering the given object as a target object of the mappings. * @param removeOppositeMappings True: mappings contains is the opposite hash maps will be removed too. * @since 0.2 */ protected void removeMappings(final Object object, final Class clazz, final Map uniqueMaps, final Map> multiMaps, final boolean removeUsingTarget, final boolean removeOppositeMappings) { if(object==null) return ; final List mappings = multiMaps.get(object); IMapping mapping = uniqueMaps.get(object); //TODO manage mappings with several sources or targets. if(mapping!=null && (clazz==null || clazz.isInstance(mapping))) { // Removing the mapping. uniqueMaps.remove(object); // Removing the opposite mappings if required. if(removeOppositeMappings) removeOppositeMapping(mapping, removeUsingTarget); // Freeing the mapping. mapping.clear(); } if(mappings!=null) { int i=0; while(i uMappings, final Map> mMappings) { for(final IMapping mapping : uMappings.values()) buf.append(mapping).append('\n'); for(final List mappings : mMappings.values()) for(final IMapping mapping : mappings) buf.append(mapping).append('\n'); } private void removeOppositeMapping(final IMapping mapping, final boolean removeUsingTarget) { if(mapping==null) return; final Object ref; final Map uniqueMap; final Map> uniqueMultiMap; if(removeUsingTarget) { ref = mapping.getSource(); uniqueMap = uniqueMappings; uniqueMultiMap = multiMappings; } else { ref = mapping.getTarget(); uniqueMap = invertedUniqueMappings; uniqueMultiMap = invertedMultiMappings; } uniqueMap.values().remove(mapping); final List maps = uniqueMultiMap.get(ref); if(maps!=null) { maps.remove(mapping); if(maps.isEmpty()) uniqueMultiMap.remove(ref); } } @Override public void removeMappingsUsingSource(final Object source) { removeMappingsUsingSource(source, null); } @Override public void removeMappingsUsingTarget(final Object target) { removeMappingsUsingTarget(target, null); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/Object2ObjectMapping.java000066400000000000000000000044601301161664300315550ustar00rootroot00000000000000package org.malai.mapping; /** * This interface defines the concept of mapping that link a source object to a target object.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/16/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the source object of the mapping. * @param The type of the target object of the mapping. */ public abstract class Object2ObjectMapping implements IMapping { /** The source object. */ protected S sourceObject; /** The target object. */ protected T targetObject; /** * Creates the mapping. * @param source The source object. * @param target The target object. * @throws IllegalArgumentException If one of the given arguments is null or if they are the same object. * @since 0.2 */ public Object2ObjectMapping(final S source, final T target) { super(); if(source==null || target==null || source==target) throw new IllegalArgumentException(); sourceObject = source; targetObject = target; } @Override public S getSource() { return sourceObject; } @Override public T getTarget() { return targetObject; } @Override public void onObjectAdded(final Object list, final Object object, final int index) { // } @Override public void onObjectMoved(final Object list, final Object object, final int srcIndex, final int targetIndex) { // } @Override public void onObjectRemoved(final Object list, final Object object, final int index) { // } @Override public void onListCleaned(final Object list) { // } @Override public void onObjectReplaced(final IUnary object, final Object replacedObject) { // } @Override public void init() { if(sourceObject!=null) onObjectModified(sourceObject); } @Override public void clear() { sourceObject = null; targetObject = null; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/SymmetricList2ListMapping.java000066400000000000000000000050541301161664300326640ustar00rootroot00000000000000package org.malai.mapping; import java.util.List; /** * This interface defines the concept of mapping that link source objects with target objects.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/15/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the source list of the mapping. * @param The type of the target list of the mapping. */ public abstract class SymmetricList2ListMapping extends List2ListMapping { /** * {@link List2ListMapping#List2ListMapping(List, List)} */ public SymmetricList2ListMapping(final List source, final List target) { super(source, target); } /** * Creates an instance of the target type using the given source object. * @param sourceObject The source object used to create the target object. * @return The created target object. * @since 0.2 */ protected abstract F createTargetObject(final Object sourceObject); @Override public void onObjectAdded(final Object list, final Object object, final int index) { if(index==-1 || index>=target.size()) target.add(createTargetObject(object)); else target.add(index, createTargetObject(object)); } @Override public void onObjectModified(final Object object) { // Nothing to do. } @Override public void onObjectMoved(final Object list, final Object object, final int srcIndex, final int targetIndex) { final int srcPos = srcIndex==-1 ? target.size()-1 : srcIndex; final F targetObj = target.remove(srcPos); if(targetIndex== target.size() || targetIndex==-1) target.add(targetObj); else target.add(targetIndex, targetObj); } @Override public void onObjectRemoved(final Object list, final Object object, final int index) { if(index==-1) target.remove(target.size()-1); else target.remove(index); } @Override public void onListCleaned(final Object list) { target.clear(); } @Override public void init() { onListCleaned(source); } @Override public void onObjectReplaced(final IUnary object, final Object replcaedObject) { // Nothing to do. } } SynchroSymmetricList2ListMapping.java000066400000000000000000000054201301161664300341500ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mappingpackage org.malai.mapping; import java.util.List; /** * This interface defines the concept of mapping that link source objects with target objects. * The modification of the target list are synchronised in opposite to SymmetricList2ListMapping
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2013-03-01
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the source list of the mapping. * @param The type of the target list of the mapping. */ public abstract class SynchroSymmetricList2ListMapping extends List2ListMapping { /** * {@link List2ListMapping#List2ListMapping(List, List)} */ public SynchroSymmetricList2ListMapping(final List source, final List target) { super(source, target); } /** * Creates an instance of the target type using the given source object. * @param sourceObject The source object used to create the target object. * @return The created target object. * @since 0.2 */ protected abstract F createTargetObject(final Object sourceObject); @Override public void onObjectAdded(final Object list, final Object object, final int index) { synchronized(target){ if(index==-1 || index>=target.size()) target.add(createTargetObject(object)); else target.add(index, createTargetObject(object)); } } @Override public void onObjectModified(final Object object) { // Nothing to do. } @Override public void onObjectMoved(final Object list, final Object object, final int srcIndex, final int targetIndex) { synchronized(target){ final int srcPos = srcIndex==-1 ? target.size()-1 : srcIndex; final F targetObj = target.remove(srcPos); if(targetIndex== target.size() || targetIndex==-1) target.add(targetObj); else target.add(targetIndex, targetObj); } } @Override public void onObjectRemoved(final Object list, final Object object, final int index) { synchronized(target){ if(index==-1) target.remove(target.size()-1); else target.remove(index); } } @Override public void onListCleaned(final Object list) { synchronized(target){target.clear();} } @Override public void init() { onListCleaned(source); } @Override public void onObjectReplaced(final IUnary object, final Object replacedObject) { // Nothing to do. } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/mapping/Unary2UnaryMapping.java000066400000000000000000000047521301161664300313410ustar00rootroot00000000000000package org.malai.mapping; /** * This interface defines the concept of mapping that link a source value (unary relation) to a target one.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/15/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of the source unary relation of the mapping. * @param The type of the target unary relation of the mapping. */ public abstract class Unary2UnaryMapping implements IMapping { /** The source unary relation of the mapping. */ protected IUnary sourceObject; /** The target unary relation of the mapping. */ protected IUnary targetObject; /** * Creates a unary relation to unary relation mapping. * @param source The source unary relation. * @param target The target unary relation. * @throw IllegalArgumentException If one of the given arguments is null or if they are equal. * @since 0.2 */ public Unary2UnaryMapping(final IUnary source, final IUnary target) { super(); if(source==null || target==null || source==target) throw new IllegalArgumentException(); sourceObject = source; targetObject = target; } @Override public void onObjectAdded(final Object list, final Object object, final int index) { // Cannot be applied for such a mapping. } @Override public void onObjectMoved(final Object list, final Object object, final int srcIndex, final int targetIndex) { // Cannot be applied for such a mapping. } @Override public void onObjectRemoved(final Object list, final Object object, final int index) { // Cannot be applied for such a mapping. } @Override public void init() { if(sourceObject!=null) onObjectReplaced(sourceObject, sourceObject.getValue()); } @Override public void onListCleaned(final Object list) { // } @Override public void clear() { sourceObject = null; targetObject = null; } @Override public Object getSource() { return sourceObject; } @Override public Object getTarget() { return targetObject; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/picking/000077500000000000000000000000001301161664300247445ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/picking/Pickable.java000066400000000000000000000023071301161664300273230ustar00rootroot00000000000000package org.malai.picking; /** * Defines an interface for objects that can be picked. A pickable object must be contained by a picker object.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/10/2010
* @author Arnaud BLOUIN * @version 0.1 * @since 0.1 */ public interface Pickable { /** * Tests if the given point is into the pickable object. * @param x The x-coordinate of the point to test. * @param y The y-coordinate of the point to test. * @return True if the given point is into the pickable object. * @since 0.1 */ boolean contains(final double x, final double y); /** * @return The picker object that contains the pickable object. * @since 0.2 */ Picker getPicker(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/picking/Picker.java000066400000000000000000000044311301161664300270260ustar00rootroot00000000000000package org.malai.picking; /** * Defines an interface for objects that contains pickable and picker objects.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/10/2010
* @author Arnaud BLOUIN * @version 0.1 * @since 0.1 */ public interface Picker { /** * @param x The x-coordinate of the position used to get the pickable object. * @param y The y-coordinate of the position used to get the pickable object. * @return The pickable object at the given position. * @since 0.1 */ Pickable getPickableAt(final double x, final double y); /** * @param x The x-coordinate of the position used to get the picker object. * @param y The y-coordinate of the position used to get the picker object. * @return The pickable object at the given position. * @since 0.1 */ Picker getPickerAt(final double x, final double y); // /** // * @param x The x-coordinate of the position to convert. // * @param y The y-coordinate of the position to convert. // * @param o An object contained by the calling picker. This function will computed the real position of the given // * point in o. // * @return Converts the given point in to fit the coordinates of the given object contained by the picker. // * For instance, given an object o1 that contains an other object o2 at position (10, 10). o1.getRelativePoint(30, 30, o2) // * will return (20, 20). // * @since 0.1 // */ // Point2D getRelativePoint(final double x, final double y, final Object o); /** * Tests if the given object is contained by the calling picker. * @param obj The object to test. * @return True: the given object is contained by the calling picker. * @since 0.1 */ boolean contains(final Object obj);//TODO Should obj be a Pickable? } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/preferences/000077500000000000000000000000001301161664300256215ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/preferences/Preferenciable.java000066400000000000000000000042541301161664300313770ustar00rootroot00000000000000package org.malai.preferences; import org.w3c.dom.Document; import org.w3c.dom.Element; /** * The interface can be applied on classes which can preferences can be saved into an XML document.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 01/10/11 * @since 0.2 * @version 0.2 */ public interface Preferenciable { /** * Saves the parameters of the instrument into an XML tag. * @param generalPreferences True: this operation is called to save the general preferences of the interactive system. * Otherwise, it is called to save a presentation in a document. This parameter is useful when different information * must be saved during a presentation backup or a general preferences backup. * @param nsURI The namespace that must be added to tags corresponding to the instrument's parameters. * @param document The XML document. * @param root The root element that will contains the instrument's parameters. * @since 0.2 */ void save(final boolean generalPreferences, final String nsURI, final Document document, final Element root); /** * Loads data save in an XML document. * @param generalPreferences True: this operation is called to load the general preferences of the interactive system. * Otherwise, it is called to load a presentation in a document. This parameter is useful when different information * must be loaded during a presentation backup or a general preferences backup. * @param meta The meta data element. * @param nsURI The namespace that must be added to tags corresponding to the instrument's parameters. * @since 0.2 */ void load(final boolean generalPreferences, final String nsURI, final Element meta); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/presentation/000077500000000000000000000000001301161664300260335ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/presentation/AbstractPresentation.java000066400000000000000000000016151301161664300330400ustar00rootroot00000000000000package org.malai.presentation; import org.malai.properties.Modifiable; import org.malai.properties.Reinitialisable; /** * The abstract presentation defines the manipulated data model.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 05/24/10 * @since 0.1 * @version 0.1 */ public interface AbstractPresentation extends Modifiable, Reinitialisable { // } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/presentation/ConcretePresentation.java000066400000000000000000000020461301161664300330360ustar00rootroot00000000000000package org.malai.presentation; import org.malai.preferences.Preferenciable; import org.malai.properties.Modifiable; import org.malai.properties.Reinitialisable; /** * The concrete presentation is the representation of the abstract presentation.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 05/24/10 * @since 0.1 * @version 0.1 */ public interface ConcretePresentation extends Preferenciable, Modifiable, Reinitialisable { /** * Updates the concrete presentation. * @since 0.2 */ void update(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/presentation/Presentation.java000066400000000000000000000056341301161664300313610ustar00rootroot00000000000000package org.malai.presentation; import org.malai.properties.Modifiable; import org.malai.properties.Reinitialisable; /** * A presentation contains an abstract presentation and a concrete presentation. * The goal of a presentation is to provide users with data (the abstract presentation) transformed * to be displayable (the concrete presentation).
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 05/24/10 * @since 0.1 * @version 0.1 * @param
The type of the abstract presentation. * @param The type of the concrecte presentation. */ public class Presentation implements Modifiable, Reinitialisable { /** The abstract presentation, i.e. the manipulated data model. */ protected final A abstractPresentation; /** The concrete presentation, i.e. the representation of the abstract presentation. */ protected final C concretePresentation; /** * Creates a presentation. * @param absPres The abstract presentation, i.e. the manipulated data model. * @param concPres The concrete presentation, i.e. the representation of the abstract presentation. * @throws IllegalArgumentException If one of the given arguments is null. * @since 0.1 */ public Presentation(final A absPres, final C concPres) { if(absPres==null || concPres==null) throw new IllegalArgumentException(); abstractPresentation = absPres; concretePresentation = concPres; } @Override public void setModified(final boolean modified) { abstractPresentation.setModified(modified); concretePresentation.setModified(modified); } @Override public boolean isModified() { return abstractPresentation.isModified() || concretePresentation.isModified(); } /** * @return The abstract presentation, i.e. the manipulated data model. * @since 0.1 */ public A getAbstractPresentation() { return abstractPresentation; } /** * @return The concrete presentation, i.e. the representation of the abstract presentation. * @since 0.1 */ public C getConcretePresentation() { return concretePresentation; } /** * Updates the presentation. * @since 0.2 */ public void update() { concretePresentation.update(); } /** * Reinitialises the presentation (its concrete and abstract presentations). * @since 0.2 */ @Override public void reinit() { abstractPresentation.reinit(); concretePresentation.reinit(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/properties/000077500000000000000000000000001301161664300255145ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/properties/Modifiable.java000066400000000000000000000022101301161664300304050ustar00rootroot00000000000000package org.malai.properties; /** * Defines an interface for object that can be modified and set as modified. This interface can also be used * to notify objects that the Modifiable object as been modified.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* LaTeXDraw is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* LaTeXDraw is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/31/2011
* @author Arnaud BLOUIN * @since 0.2 */ public interface Modifiable { /** * Sets the Modifiable object as modified. * @param modified True: the element is will tagged as modified. * @since 0.2 */ void setModified(final boolean modified); /** * @return True: the object has been modified. False otherwise. * @since 3.0 */ boolean isModified(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/properties/Reinitialisable.java000066400000000000000000000014771301161664300314700ustar00rootroot00000000000000package org.malai.properties; /** * Defines an interface for object that can be reinitialised.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* LaTeXDraw is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* LaTeXDraw is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 08/09/2011
* @author Arnaud BLOUIN * @since 0.2 */ public interface Reinitialisable { /** * Reinitialises the object. * @since 0.2 */ void reinit(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/properties/Zoomable.java000066400000000000000000000040251301161664300301300ustar00rootroot00000000000000package org.malai.properties; import java.awt.Point; import java.awt.geom.Point2D; /** * Defines an interface to zoomable objects.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 05/11/2010
* @author Arnaud BLOUIN * @version 0.1 * @since 0.1 */ public interface Zoomable { /** * @return The zoom increment used when zooming in/out. */ double getZoomIncrement(); /** * @return The maximal level of zooming allowed. */ double getMaxZoom(); /** * @return The minimal level of zooming allowed. */ double getMinZoom(); /** * @return The zoom level. * @since 0.1 */ double getZoom(); /** * Zooms in the zoomable object. * @param zoomingLevel The zooming level. * @param x The X-coordinate of the location to zoom. * @param y The Y-coordinate of the location to zoom. * @since 0.1 */ void setZoom(final double x, final double y, final double zoomingLevel); /** * Transforms the given point in a point which coordinates have been modified to * take account of the zoom level. * @param x The X-coordinate of the point to modify. * @param y The Y-coordinate of the point to modify. * @return The transformed point. * @since 0.2 */ Point2D getZoomedPoint(final double x, final double y); /** * Transforms the given point in a point which coordinates have been modified to * take account of the zoom level. * @param pt The point to transform. * @return The transformed point. Returns (0,0) if the given point is null. * @since 0.2 */ Point2D getZoomedPoint(final Point pt); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/stateMachine/000077500000000000000000000000001301161664300257255ustar00rootroot00000000000000MustAbortStateMachineException.java000066400000000000000000000016461301161664300346050ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/stateMachinepackage org.malai.stateMachine; /** * This exception can be used when an interaction must be stopped.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 10/10/2009
* @author Arnaud BLOUIN * @since 0.1 */ public class MustAbortStateMachineException extends Exception { private static final long serialVersionUID = 1L; /** * Creates the exception. */ public MustAbortStateMachineException() { super(); } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/stateMachine/SourceableState.java000066400000000000000000000016751301161664300316660ustar00rootroot00000000000000package org.malai.stateMachine; /** * This interface defines a state that can be the source state of a transition.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 11/03/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface SourceableState extends State { /** * @throws MustAbortStateMachineException To launch when the state machine must stop. */ void onOutgoing() throws MustAbortStateMachineException; } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/stateMachine/State.java000066400000000000000000000031621301161664300276520ustar00rootroot00000000000000package org.malai.stateMachine; import java.util.List; /** * This interface defines the notion of state that composes a state machine.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 11/03/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface State { /** * Adds a transition to the state. * @param trans The new transition. Must not be null. * @since 0.1 */ void addTransition(final Transition trans); /** * @return The name of the state. * @since 0.1 */ String getName(); /** * @return The transitions that leaves the state. * @since 0.1 */ List getTransitions(); /** * @param index The position of the transition to get. * @return The corresponding transition or null if the given index is not valid. * @since 0.2 */ Transition getTransition(final int index); /** * Sets the state machine of the state. * @param sm The new state machine. If null, nothing is done. * @since 0.2 */ void setStateMachine(final StateMachine sm); /** * @return The state machine that contains the state. * @since 0.2 */ StateMachine getStateMachine(); }malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/stateMachine/StateMachine.java000066400000000000000000000046331301161664300311430ustar00rootroot00000000000000package org.malai.stateMachine; /** * This interface defines the notion of state machine.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 01/09/2011
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface StateMachine { /** Terminates the state machine. * @throws MustAbortStateMachineException If something happens requiring the interaction to abort. * */ void onTerminating() throws MustAbortStateMachineException; /** Aborts the state machine. */ void onAborting(); /** Starts the state machine. * @throws MustAbortStateMachineException If something happens requiring the interaction to abort. * */ void onStarting() throws MustAbortStateMachineException; /** Updates the state machine. * @throws MustAbortStateMachineException If something happens requiring the interaction to abort. * */ void onUpdating() throws MustAbortStateMachineException; /** * Adds a state to the state machine. * @param state The state to add. Must not be null. * @since 0.2 */ void addState(final State state); /** * Reinits the state machine. * @since 0.2 */ void reinit(); /** * Defines if the state machine is activated. * @param activated True: the state machine will be activated. * @since 0.2 */ void setActivated(final boolean activated); /** * @return The current state of the running state machine. Or null when the machine is not running. * @since 2.0 */ State getCurrentState(); /** * @return True or false depending on whether the state machine is activated. * @since 2.0 */ boolean isActivated(); /** * Checks whether the transition can be executed and executes it when possible. * @param transition The transition to check. * @return True: the transition has been executed. False otherwise. */ boolean checkTransition(final Transition transition); /** * @return True: the state machine is running. * @since 0.2 */ boolean isRunning(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/stateMachine/TargetableState.java000066400000000000000000000016751301161664300316540ustar00rootroot00000000000000package org.malai.stateMachine; /** * This interface defines a state that can be the target state of a transition.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 11/03/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface TargetableState extends State { /** * @throws MustAbortStateMachineException To launch when the state machine must stop. */ void onIngoing() throws MustAbortStateMachineException; } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/stateMachine/Transition.java000066400000000000000000000027611301161664300307300ustar00rootroot00000000000000package org.malai.stateMachine; /** * This interface defines the notion of transition of a state machine.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 01/09/2011
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public interface Transition { /** * Performs the actions to do when the transition is executed. * Should be overridden. * @since 0.2 */ void action(); /** * @return True: the condition defining if the transition can be executed is correct. * By default: true. Should be overridden. * @since 0.2 */ boolean isGuardRespected(); /** * @return The source state of the transition. * @since 0.2 */ SourceableState getInputState(); /** * @return The target state of the transition. * @since 0.2 */ TargetableState getOutputState(); /** * @return The ID of the HID that produced the transition. * @since 0.2 */ int getHid(); /** * @param hid The ID of the HID that produced the transition. * @since 0.2 */ void setHid(int hid); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/ui/000077500000000000000000000000001301161664300237355ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/ui/UI.java000066400000000000000000000042341301161664300251200ustar00rootroot00000000000000package org.malai.ui; import java.util.List; import org.malai.instrument.Instrument; import org.malai.preferences.Preferenciable; import org.malai.presentation.AbstractPresentation; import org.malai.presentation.ConcretePresentation; import org.malai.presentation.Presentation; import org.malai.properties.Modifiable; import org.malai.properties.Reinitialisable; /** * Defines the concept of User Interface.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN */ public interface UI> extends Modifiable, Reinitialisable, Preferenciable { //FIXME java 8: use default implementation to factorise the code with the other components. /** * @return The instruments of the interactive system. * @since 0.2 */ Instrument[] getInstruments(); /** * Initialises the presentations of the UI. * @since 0.2 */ void initialisePresentations(); /** * Updates the presentations. * @since 0.2 */ void updatePresentations(); /** * Allows to get the presentation which abstract and concrete presentations match the given classes. * @param absPresClass The class of the abstract presentation to find. * @param concPresClass The class of the concrete presentation to find. * @return The found presentation or null. * @since 0.2 */
Presentation getPresentation(final Class absPresClass, final Class concPresClass); /** * @return The presentations of the interactive system. * @since 0.2 */ List> getPresentations(); /** * @return The composer that composes the UI. * @since 0.2 */ S getComposer(); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/ui/UIComposer.java000066400000000000000000000035471301161664300266360ustar00rootroot00000000000000package org.malai.ui; /** * A UI composer is a object that composes a user interface using instruments and presentations.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 10/31/2010
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 * @param The type of widget produced by the composer. * @param The type of root widget class of the GUI toolkit. * @param The type of the progress bar in the GUI toolkit. */ public abstract class UIComposer { /** The widget composed by the composer. */ protected T widget; /** * Creates the composer. * @since 0.2 */ public UIComposer() { super(); } /** * This method composes the user interface using instruments, presentations and widgets of the interactive system. * @param progressBar The progress bar that can be used to show the progress of the UI composition. Can be null. */ public abstract void compose(final S progressBar); /** * Changes the visibility of the given widget and may launch a process of recomposition/adaptation of the UI if needed. * @param widget The widget to change its visibility. * @param visible True: the widget will be visible. * @since 0.2 */ public abstract void setWidgetVisible(final R widget, final boolean visible); /** * @return The widget composed by the composer. * @since 0.2 */ public T getWidget() { return widget; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/undo/000077500000000000000000000000001301161664300242655ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/undo/EmptyUndoHandler.java000066400000000000000000000022331301161664300303520ustar00rootroot00000000000000package org.malai.undo; /** * An implementation of UndoHandler that does nothing. Useful to avoid implementing all the operations.
* This file is part of libMalai. * Copyright (c) 2005-2015 Arnaud BLOUIN * * libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. * * libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * @author Arnaud BLOUIN */ public class EmptyUndoHandler implements UndoHandler { /** * Creates an undo handler that does nothing. */ public EmptyUndoHandler() { super(); } @Override public void onUndoableCleared() { // To override } @Override public void onUndoableAdded(final Undoable undoable) { // To override } @Override public void onUndoableUndo(final Undoable undoable) { // To override } @Override public void onUndoableRedo(final Undoable undoable) { // To override } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/undo/UndoCollector.java000066400000000000000000000131731301161664300277110ustar00rootroot00000000000000package org.malai.undo; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.List; /** * Defines a collector of undone/redone objects.
* This file is part of libMalai. * Copyright (c) 2005-2015 Arnaud BLOUIN * * libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. * * libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * @date 05/23/2010 * @author Arnaud BLOUIN * @since 0.1 */ public final class UndoCollector { /** The default undo/redo collector. */ public static final UndoCollector INSTANCE = new UndoCollector(); /** The label display when there is no redo possible */ public static final String EMPTY_REDO = "redo"; /** The label display when there is no undo possible */ public static final String EMPTY_UNDO = "undo"; /** Contains the handlers of each undoable of the undo stack */ private final Deque undoHandlers; /** Contains the handlers of each undoable of the redo stack */ private final Deque redoHandlers; /** Contains the undoable objects. */ private final Deque undo; /** Contains the redoable objects. */ private final Deque redo; /** The maximal number of undo. */ private int sizeMax; /** The handlers that handles the collector. */ private final List handlers; /** This object is used to avaoid the use of null when no undoable handler are provided. */ private static final UndoHandler STUB_UNDO_HANDLER = new EmptyUndoHandler(); /** * The constructor by default. */ private UndoCollector() { super(); handlers = new ArrayList<>(); undo = new ArrayDeque<>(); redo = new ArrayDeque<>(); undoHandlers = new ArrayDeque<>(); redoHandlers = new ArrayDeque<>(); sizeMax = 30; } /** * Adds a handler to the collector. * @param handler The handler to add. Must not be null. */ public void addHandler(final UndoHandler handler) { if(handler!=null) handlers.add(handler); } /** * Removes the given handler from the collector. * @param handler The handler to remove. Must not be null. */ public void removeHandler(final UndoHandler handler) { if(handler!=null) handlers.remove(handler); } /** * Removes all the undoable objects of the collector. */ public void clear() { undo.clear(); redo.clear(); undoHandlers.clear(); redoHandlers.clear(); for(final UndoHandler h : handlers) h.onUndoableCleared(); } /** * Adds an undoable object to the collector. * @param undoable The undoable object to add. * @param undoHandler The handler that produced or is associated to the undoable object. */ public void add(final Undoable undoable, final UndoHandler undoHandler) { if(undoable!=null && sizeMax>0) { if(undo.size()==sizeMax) { undo.removeLast(); undoHandlers.removeLast(); } undo.push(undoable); // When undo handler is null, a fake object is added instead of using null. if(undoHandler==null) undoHandlers.push(STUB_UNDO_HANDLER); else undoHandlers.push(undoHandler); redo.clear(); /* The redoable objects must be removed. */ redoHandlers.clear(); for(final UndoHandler handler : handlers) handler.onUndoableAdded(undoable); } } /** * Undoes the last undoable object. */ public void undo() { if(!undo.isEmpty()) { final Undoable undoable = undo.pop(); final UndoHandler undoHandler = undoHandlers.pop(); undoable.undo(); redo.push(undoable); redoHandlers.push(undoHandler); undoHandler.onUndoableUndo(undoable); for(final UndoHandler handler : handlers) handler.onUndoableUndo(undoable); } } /** * Redoes the last undoable object. */ public void redo() { if(!redo.isEmpty()) { final Undoable undoable = redo.pop(); final UndoHandler redoHandler = redoHandlers.pop(); undoable.redo(); undo.push(undoable); undoHandlers.push(redoHandler); redoHandler.onUndoableRedo(undoable); for(final UndoHandler handler : handlers) handler.onUndoableRedo(undoable); } } /** * @return The last undoable object name or null if there is no last object. */ public String getLastUndoMessage() { return undo.isEmpty() ? null : undo.peek().getUndoName(); } /** * @return The last redoable object name or null if there is no last object. */ public String getLastRedoMessage() { return redo.isEmpty() ? null : redo.peek().getUndoName(); } /** * @return The last undoable object or null if there is no last object. */ public Undoable getLastUndo() { return undo.isEmpty() ? null : undo.peek(); } /** * @return The last redoable object or null if there is no last object. */ public Undoable getLastRedo() { return redo.isEmpty() ? null : redo.peek(); } /** * @return The max number of saved undoable objects. */ public int getSizeMax() { return sizeMax; } /** * @param max The max number of saved undoable objects. Must be great than 0. */ public void setSizeMax(final int max) { if(max>=0) { for(int i=0, nb=undo.size()-max; i getUndo() { return undo; } /** * @return The stack of saved redoable objects * @since 0.1 */ public Deque getRedo() { return redo; } } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/undo/UndoHandler.java000066400000000000000000000026321301161664300273360ustar00rootroot00000000000000package org.malai.undo; /** * This handler must help objet that want to be aware of * undone/redone event (for instance, to update some widgets).
* This file is part of libMalai. * Copyright (c) 2005-2015 Arnaud BLOUIN * * libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. * * libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * @author Arnaud BLOUIN * @since 0.1 */ public interface UndoHandler { /** * Notifies the handler that the stored undoable objects have been all removed. * @since 0.2 */ void onUndoableCleared(); /** * Actions to do when an undoable object is added to the undo register. * @param undoable The undoable object added to the undo register. * @since 0.2 */ void onUndoableAdded(final Undoable undoable); /** * Actions to do when an undoable object is undone. * @param undoable The undone object. * @since 0.2 */ void onUndoableUndo(final Undoable undoable); /** * Actions to do when an undoable object is redone. * @param undoable The redone object. * @since 0.2 */ void onUndoableRedo(final Undoable undoable); } malai-2.0+ds1/malai-core/org.malai.core/src/main/org/malai/undo/Undoable.java000066400000000000000000000016331301161664300266640ustar00rootroot00000000000000package org.malai.undo; /** * Defines an interface for undoable objects. * This file is part of libMalai. * Copyright (c) 2005-2015 Arnaud BLOUIN * * libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. * * libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * @author Arnaud BLOUIN * @date 05/23/2010 * @since 0.1 */ public interface Undoable { /** * Cancels the action. * @since 0.1 */ void undo(); /** * Redoes the cancelled action. * @since 0.1 */ void redo(); /** * @return The name of the undo action. * @since 0.1 */ String getUndoName(); } malai-2.0+ds1/malai-core/org.malai.core/src/resources/000077500000000000000000000000001301161664300225345ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/resources/res/000077500000000000000000000000001301161664300233255ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/resources/res/Redo.png000077500000000000000000000014521301161664300247310ustar00rootroot00000000000000PNG  IHDRĴl;bKGD pHYs B(xtIME #K(OIDAT8˭MkQs#4֊"T VX(m,. fGŶ ki&G373Idx0p9s.cqn} X\+ _Żi?xnSh"tIo&Eb[IeyD"pj QZ]ZrH%pS Vb@4æX\?`Qei+Y  fIy|%\3 _\t&P(emBEl E2 @xJ̯BQ;`(Yip- @Ш iUr]E-hmDŽVlrfv9 ip2 N@EDK.{[BAZa˜[ t*/MVλ?4$+}T ib@R/ °9 Oe]:7xzGt\.R(;L_*OF^5T)D Jebƣ"VeUߊcl.wXora?>V*ڡ.|eZK:Draf{pj&ǖ#s1I[ •G("OjEu3?:!nAnC:cIENDB`malai-2.0+ds1/malai-core/org.malai.core/src/resources/res/Undo.png000077500000000000000000000017631301161664300247520ustar00rootroot00000000000000PNG  IHDRĴl;bKGD pHYs B(xtIME 8?TIDAT8˭_h[UǿM{]t\u>̗"[բȊ21ʄ>QEA>>8(/ -[ctaݬڤuB{[.Yxǽ=øtnd2] iK CG43vHoCg{m`e'G*~E2ްpôS7N`U83#<F0lr/}AC"JG^G=P(=lxtÏ?=P%l-ٽuW3Y#Y\)6fzUpx{i{z%dV+ CG64 [_|i\ǟBy̷zDhCӬZ¬@O~\[I-""fx嘇tuqi*-lp/OYz? +YPu̵}GxMZ]܅սu1AE,IENDB`malai-2.0+ds1/malai-core/org.malai.core/src/test/000077500000000000000000000000001301161664300215015ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/000077500000000000000000000000001301161664300224605ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/000077500000000000000000000000001301161664300232475ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/000077500000000000000000000000001301161664300243325ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/HelperTest.java000066400000000000000000000007331301161664300272570ustar00rootroot00000000000000package test.org.malai; import java.awt.GraphicsEnvironment; import java.lang.reflect.Field; public abstract class HelperTest { public static Field getField(final Class clazz, final String name) throws SecurityException, NoSuchFieldException { final Field field = clazz.getDeclaredField(name); field.setAccessible(true); return field; } public static boolean isX11Set() { return !GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance(); } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/action/000077500000000000000000000000001301161664300256075ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/action/ActionMock.java000066400000000000000000000005001301161664300304740ustar00rootroot00000000000000package test.org.malai.action; import org.malai.action.Action; public class ActionMock extends Action { public ActionMock() { super(); } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { // } @Override public boolean canDo() { return false; } }malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/action/TestAbstractAction.java000066400000000000000000000016531301161664300322200ustar00rootroot00000000000000package test.org.malai.action; import org.junit.Before; import org.junit.Test; import org.malai.action.Action; import org.malai.instrument.Interactor; import org.malai.instrument.InstrumentImpl; public abstract class TestAbstractAction { protected T action; @Before public void setUp() { action = createAction(); } protected abstract T createAction(); @Test public abstract void testConstructor() throws Exception; @Test public abstract void testFlush() throws Exception; @Test public abstract void testDo() throws Exception; @Test public abstract void testCanDo() throws Exception; @Test public abstract void testIsRegisterable() throws Exception; @Test public abstract void testHadEffect() throws Exception; public class InstrumentMock extends InstrumentImpl { public InstrumentMock() { super(); } @Override protected void initialiseInteractors() { // } } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/action/TestAction.java000066400000000000000000000177751301161664300305500ustar00rootroot00000000000000package test.org.malai.action; import static org.junit.Assert.*; import java.lang.reflect.Field; import org.junit.Before; import org.junit.Test; import org.malai.action.Action; import org.malai.action.ActionHandler; import org.malai.action.ActionsRegistry; import org.malai.undo.Undoable; public class TestAction { protected Action action; @Before public void setUp() { action = getActionCanDo(); ActionsRegistry.INSTANCE.removeAllHandlers(); } @Test public void testActionStatusAfterCreation() { assertEquals(Action.ActionStatus.CREATED, action.getStatus()); } @Test public void testActionStatusAfterFlush() { action.flush(); assertEquals(Action.ActionStatus.FLUSHED, action.getStatus()); } @Test public void testActionCannotDoItWhenFlushed() { action.flush(); assertFalse(action.doIt()); } @Test public void testActionCannotDoItWhenDone() { action.done(); assertFalse(action.doIt()); } @Test public void testActionCannotDoItWhenAborted() { action.abort(); assertFalse(action.doIt()); } @Test public void testActionCannotDoItWhenCannotDoAndCreated() { final Action act = getActionCannotDo(); assertFalse(act.doIt()); } @Test public void testActionCannotDoItWhenCannotDoAndExecuted() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Action act = getActionCannotDo(); act.doIt(); final Field field = act.getClass().getSuperclass().getDeclaredField("status");// field.setAccessible(true); field.set(act, Action.ActionStatus.EXECUTED); assertFalse(act.doIt()); } @Test public void testActionCanDoItWhenCanDo() { final Action act = getActionCanDo(); assertTrue(act.doIt()); } @Test public void testActionIsExecutedWhenDoIt() { final Action act = getActionCanDo(); act.doIt(); assertEquals(Action.ActionStatus.EXECUTED, act.getStatus()); } boolean visitOnActionExecuted; @Test public void testNotifiedOnActionExecuted() { visitOnActionExecuted = false; ActionsRegistry.INSTANCE.addHandler(new ActionHandler() { @Override public void onUndoableUndo(final Undoable undoable) {fail();} @Override public void onUndoableRedo(final Undoable undoable) {fail();} @Override public void onUndoableAdded(final Undoable undoable) {fail();} @Override public void onActionExecuted(final Action act) { visitOnActionExecuted = true; } @Override public void onActionDone(final Action act) {fail();} @Override public void onActionCancelled(final Action act) {fail();} @Override public void onActionAdded(final Action act) {fail();} @Override public void onActionAborted(final Action act) {fail();} @Override public void onUndoableCleared() { // TODO Auto-generated method stub } }); final Action act = getActionCanDo(); act.doIt(); assertTrue(visitOnActionExecuted); } public Action getActionCanDo() { return new Action() { @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { // } @Override public boolean canDo() { return true; } }; } public Action getActionCannotDo() { return new Action() { @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { // } @Override public boolean canDo() { return false; } }; } @Test public void testActionHadEffectWhenDone() { action.done(); assertTrue(action.hadEffect()); } @Test public void testActionHadEffectWhenNotDoneAndCreated() { assertFalse(action.hadEffect()); } @Test public void testActionHadEffectWhenNotDoneAndAborted() { action.abort(); assertFalse(action.hadEffect()); } @Test public void testActionHadEffectWhenNotDoneAndFlushed() { action.flush(); assertFalse(action.hadEffect()); } @Test public void testActionHadEffectWhenNotDoneAndExecuted() { final Action act = getActionCanDo(); act.doIt(); assertFalse(act.hadEffect()); } @Test public void testActionNotCancelledByByDefault() { assertFalse(action.cancelledBy(null)); assertFalse(action.cancelledBy(getActionCanDo())); } @Test public void testActionNotDoneWhenFlushed() { action.flush(); action.done(); assertEquals(Action.ActionStatus.FLUSHED, action.getStatus()); } @Test public void testActionNotDoneWhenAborted() { action.abort(); action.done(); assertEquals(Action.ActionStatus.ABORTED, action.getStatus()); } @Test public void testActionNotDoneWhenDone() { action.done(); // Cannot visit ActionDone if already done. ActionsRegistry.INSTANCE.addHandler(new ActionHandler() { @Override public void onUndoableUndo(final Undoable undoable) {fail();} @Override public void onUndoableRedo(final Undoable undoable) {fail();} @Override public void onUndoableAdded(final Undoable undoable) {fail();} @Override public void onActionExecuted(final Action act) {fail();} @Override public void onActionDone(final Action act) {fail();} @Override public void onActionCancelled(final Action act) {fail();} @Override public void onActionAdded(final Action act) {fail();} @Override public void onActionAborted(final Action act) {fail();} @Override public void onUndoableCleared() { // TODO Auto-generated method stub } }); action.done(); } boolean visitOnActionDone; @Test public void testActionDoneWhenCreated() { visitOnActionDone = false; ActionsRegistry.INSTANCE.addHandler(new ActionHandler() { @Override public void onUndoableUndo(final Undoable undoable) {fail();} @Override public void onUndoableRedo(final Undoable undoable) {fail();} @Override public void onUndoableAdded(final Undoable undoable) {fail();} @Override public void onActionExecuted(final Action act) {fail();} @Override public void onActionDone(final Action act) { visitOnActionDone = true; } @Override public void onActionCancelled(final Action act) {fail();} @Override public void onActionAdded(final Action act) {fail();} @Override public void onActionAborted(final Action act) {fail();} @Override public void onUndoableCleared() { // TODO Auto-generated method stub } }); action.done(); assertEquals(Action.ActionStatus.DONE, action.getStatus()); assertTrue(visitOnActionDone); } @Test public void testActionDoneWhenExecuted() { final Action a = getActionCanDo(); a.doIt(); visitOnActionDone = false; ActionsRegistry.INSTANCE.addHandler(new ActionHandler() { @Override public void onUndoableUndo(final Undoable undoable) {fail();} @Override public void onUndoableRedo(final Undoable undoable) {fail();} @Override public void onUndoableAdded(final Undoable undoable) {fail();} @Override public void onActionExecuted(final Action act) {fail();} @Override public void onActionDone(final Action act) { visitOnActionDone = true; } @Override public void onActionCancelled(final Action act) {fail();} @Override public void onActionAdded(final Action act) {fail();} @Override public void onActionAborted(final Action act) {fail();} @Override public void onUndoableCleared() { // TODO Auto-generated method stub } }); a.done(); assertEquals(Action.ActionStatus.DONE, a.getStatus()); assertTrue(visitOnActionDone); } @Test public void testToStringNotNull() { assertNotNull(action.toString()); } @Test public void testIsDoneWhenCreated() { assertFalse(action.isDone()); } @Test public void testIsDoneWhenAborted() { action.abort(); assertFalse(action.isDone()); } @Test public void testIsDoneWhenFlushed() { action.flush(); assertFalse(action.isDone()); } @Test public void testIsDoneWhenDone() { action.done(); assertTrue(action.isDone()); } @Test public void testIsDoneWhenExecuted() { final Action a = getActionCanDo(); a.doIt(); assertFalse(action.isDone()); } @Test public void testAbort() { assertNotSame(Action.ActionStatus.ABORTED, action.getStatus()); action.abort(); assertEquals(Action.ActionStatus.ABORTED, action.getStatus()); } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/action/TestActionRegistry.java000066400000000000000000000311651301161664300322660ustar00rootroot00000000000000package test.org.malai.action; import static org.junit.Assert.*; import java.lang.reflect.Field; import java.util.List; import org.junit.Before; import org.junit.Test; import org.malai.action.Action; import org.malai.action.Action.ActionStatus; import org.malai.action.ActionHandler; import org.malai.action.ActionsRegistry; import org.malai.undo.UndoCollector; import org.malai.undo.Undoable; import test.org.malai.HelperTest; public class TestActionRegistry { boolean visited; @Before public void setUp() { ActionsRegistry.INSTANCE.removeAllHandlers(); ActionsRegistry.INSTANCE.getActions().clear(); ActionsRegistry.INSTANCE.setSizeMax(30); UndoCollector.INSTANCE.clear(); } @SuppressWarnings("unchecked") public List getListHandler() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Field field = HelperTest.getField(ActionsRegistry.INSTANCE.getClass(), "handlers"); return (List) field.get(ActionsRegistry.INSTANCE); } @Test public void testGetSetSizeMax() { ActionsRegistry.INSTANCE.setSizeMax(55); assertEquals(55, ActionsRegistry.INSTANCE.getSizeMax()); ActionsRegistry.INSTANCE.setSizeMax(Integer.MAX_VALUE); assertEquals(Integer.MAX_VALUE, ActionsRegistry.INSTANCE.getSizeMax()); ActionsRegistry.INSTANCE.setSizeMax(0); assertEquals(0, ActionsRegistry.INSTANCE.getSizeMax()); ActionsRegistry.INSTANCE.setSizeMax(-1); assertEquals(0, ActionsRegistry.INSTANCE.getSizeMax()); ActionsRegistry.INSTANCE.setSizeMax(Integer.MIN_VALUE); assertEquals(0, ActionsRegistry.INSTANCE.getSizeMax()); } @Test public void testSetSizeMaxRemovesAction() { final List handlers = ActionsRegistry.INSTANCE.getActions(); final Action action1 = new ActionMock(); final Action action2 = new ActionMock(); ActionsRegistry.INSTANCE.setSizeMax(10); ActionsRegistry.INSTANCE.addAction(action1, new ActionHandlerMock()); ActionsRegistry.INSTANCE.addAction(action2, new ActionHandlerMock()); ActionsRegistry.INSTANCE.setSizeMax(1); assertEquals(ActionStatus.FLUSHED, action1.getStatus()); assertEquals(ActionStatus.CREATED, action2.getStatus()); assertEquals(1, handlers.size()); assertEquals(action2, handlers.get(0)); ActionsRegistry.INSTANCE.setSizeMax(0); assertEquals(ActionStatus.FLUSHED, action2.getStatus()); assertEquals(0, handlers.size()); } @Test public void testAbortActionNull() { ActionsRegistry.INSTANCE.abortAction(null); } @Test public void testAbortActionFlush() { final Action action = new ActionMock(); ActionsRegistry.INSTANCE.abortAction(action); assertEquals(Action.ActionStatus.FLUSHED, action.getStatus()); } @Test public void testAbortActionNotify() { final Action action = new ActionMock(); visited = false; ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock() { @Override public void onActionAborted(final Action act) { visited = true; } }); ActionsRegistry.INSTANCE.abortAction(action); assertTrue(visited); } @Test public void testAbortActionRemoved() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Action action = new ActionMock(); ActionsRegistry.INSTANCE.addAction(action, new ActionHandlerMock()); ActionsRegistry.INSTANCE.abortAction(action); final List handlers = getListHandler(); assertTrue(handlers.isEmpty()); } @Test public void testGetActionThatExists() { final Action action1 = new ActionMock(); final Action action2 = new ActionMock(); ActionsRegistry.INSTANCE.addAction(action1, new ActionHandlerMock()); ActionsRegistry.INSTANCE.addAction(action2, new ActionHandlerMock()); assertEquals(action1, ActionsRegistry.INSTANCE.getAction(ActionMock.class)); } @Test public void testGetActionThatDoesNotExist() { ActionsRegistry.INSTANCE.addAction(new ActionMock(), new ActionHandlerMock()); assertNull(ActionsRegistry.INSTANCE.getAction(ActionMock2.class)); } @Test public void testGetActionNull() { ActionsRegistry.INSTANCE.addAction(new ActionMock(), new ActionHandlerMock()); assertNull(ActionsRegistry.INSTANCE.getAction(null)); } @Test public void testRemoveAllHandler() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock()); ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock()); final List handlers = getListHandler(); ActionsRegistry.INSTANCE.removeAllHandlers(); assertTrue(handlers.isEmpty()); } @Test public void testRemoveHandler() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final ActionHandler handler = new ActionHandlerMock(); ActionsRegistry.INSTANCE.addHandler(handler); ActionsRegistry.INSTANCE.removeHandler(null); final List handlers = getListHandler(); assertEquals(1, handlers.size()); ActionsRegistry.INSTANCE.removeHandler(handler); assertTrue(handlers.isEmpty()); } @Test public void testAddHandler() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { ActionsRegistry.INSTANCE.addHandler(null); final List handlers = getListHandler(); assertTrue(handlers.isEmpty()); ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock()); assertEquals(1, handlers.size()); } @Test public void testRemoveActionNull() { ActionsRegistry.INSTANCE.addAction(new ActionMock(), new ActionHandlerMock()); ActionsRegistry.INSTANCE.removeAction(null); assertEquals(1, ActionsRegistry.INSTANCE.getActions().size()); } @Test public void testRemoveActionNotNull() { final Action action = new ActionMock(); ActionsRegistry.INSTANCE.addAction(action, new ActionHandlerMock()); ActionsRegistry.INSTANCE.removeAction(action); assertTrue(ActionsRegistry.INSTANCE.getActions().isEmpty()); assertEquals(Action.ActionStatus.FLUSHED, action.getStatus()); } @Test public void testOnActionExecuted() { visited = false; ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock()); ActionsRegistry.INSTANCE.onActionExecuted(null); ActionsRegistry.INSTANCE.removeAllHandlers(); final Action a = new ActionMock(); ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock() { @Override public void onActionExecuted(final Action act) { visited = true; assertEquals(a, act); } }); ActionsRegistry.INSTANCE.onActionExecuted(a); assertTrue(visited); } @Test public void testOnActionDone() { visited = false; ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock()); ActionsRegistry.INSTANCE.onActionDone(null); ActionsRegistry.INSTANCE.removeAllHandlers(); final Action a = new ActionMock(); ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock() { @Override public void onActionDone(final Action act) { visited = true; assertEquals(a, act); } }); ActionsRegistry.INSTANCE.onActionDone(a); assertTrue(visited); } @Test public void testGetActionsNotNull() { assertNotNull(ActionsRegistry.INSTANCE.getActions()); } @Test public void testCancelsActionNull() { ActionsRegistry.INSTANCE.cancelActions(null); assertTrue(ActionsRegistry.INSTANCE.getActions().isEmpty()); } @Test public void testCancelsActionNotNullDoNotCancel() { final Action act = new ActionMock(); ActionsRegistry.INSTANCE.addAction(act, new ActionHandlerMock()); ActionsRegistry.INSTANCE.cancelActions(new ActionMock2()); assertEquals(1, ActionsRegistry.INSTANCE.getActions().size()); assertNotSame(Action.ActionStatus.FLUSHED, act.getStatus()); } @Test public void testCancelsActionNotNullDoesCancel() { visited = false; final Action act = new ActionMock2(); ActionsRegistry.INSTANCE.addAction(act, new ActionHandlerMock()); ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock() { @Override public void onActionCancelled(final Action a) { visited = true; assertEquals(act, a); } }); ActionsRegistry.INSTANCE.cancelActions(new ActionMock()); assertTrue(ActionsRegistry.INSTANCE.getActions().isEmpty()); assertEquals(Action.ActionStatus.FLUSHED, act.getStatus()); assertTrue(visited); } @Test public void testAddActionCannotAddBecauseNullOrAlreadyAdded() { final Action action = new ActionMock(); ActionsRegistry.INSTANCE.getActions().add(action); ActionsRegistry.INSTANCE.addAction(null, new ActionHandlerMock()); assertEquals(1, ActionsRegistry.INSTANCE.getActions().size()); ActionsRegistry.INSTANCE.addAction(new ActionMock2(), null); assertEquals(1, ActionsRegistry.INSTANCE.getActions().size()); ActionsRegistry.INSTANCE.addAction(null, null); assertEquals(1, ActionsRegistry.INSTANCE.getActions().size()); ActionsRegistry.INSTANCE.addAction(action, new ActionHandlerMock()); assertEquals(1, ActionsRegistry.INSTANCE.getActions().size()); } @Test public void testAddActionCancelsAction() { visited = false; final Action action = new ActionMock2(); ActionsRegistry.INSTANCE.getActions().add(action); ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock() { @Override public void onActionCancelled(final Action a) { visited = true; assertEquals(action, a); } @Override public void onActionAdded(final Action a) {// } }); ActionsRegistry.INSTANCE.addAction(new ActionMock(), new ActionHandlerMock()); assertEquals(1, ActionsRegistry.INSTANCE.getActions().size()); assertTrue(visited); } @Test public void testAddActionNotifyHandlers() { visited = false; ActionsRegistry.INSTANCE.addHandler(new ActionHandlerMock() { @Override public void onActionAdded(final Action a) { visited = true; } }); ActionsRegistry.INSTANCE.addAction(new ActionMock(), new ActionHandlerMock()); assertTrue(visited); } @Test public void testAddActionRemovesActionWhenMaxCapacity() { final Action action = new ActionMock(); final Action action2 = new ActionMock(); ActionsRegistry.INSTANCE.setSizeMax(1); ActionsRegistry.INSTANCE.getActions().add(action2); ActionsRegistry.INSTANCE.addAction(action, new ActionHandlerMock()); assertEquals(1, ActionsRegistry.INSTANCE.getActions().size()); assertEquals(action, ActionsRegistry.INSTANCE.getActions().get(0)); assertEquals(Action.ActionStatus.FLUSHED, action2.getStatus()); } @Test public void testAddActionMaxCapacityIs0() { ActionsRegistry.INSTANCE.setSizeMax(0); ActionsRegistry.INSTANCE.addAction(new ActionMock(), new ActionHandlerMock()); assertTrue(ActionsRegistry.INSTANCE.getActions().isEmpty()); } @Test public void testAddActionAddsUndoableCollector() { final Action action = new ActionUndoableMock(); ActionsRegistry.INSTANCE.addAction(action, new ActionHandlerMock()); assertEquals(action, UndoCollector.INSTANCE.getLastUndo()); } private class ActionHandlerMock implements ActionHandler { public ActionHandlerMock() { super(); } @Override public void onUndoableUndo(final Undoable undoable) {fail();} @Override public void onUndoableRedo(final Undoable undoable) {fail();} @Override public void onUndoableAdded(final Undoable undoable) {fail();} @Override public void onActionExecuted(final Action act) {fail();} @Override public void onActionDone(final Action act) {fail();} @Override public void onActionCancelled(final Action act) {fail();} @Override public void onActionAdded(final Action act) {fail();} @Override public void onActionAborted(final Action act) {fail();} @Override public void onUndoableCleared() { // TODO Auto-generated method stub } } private class ActionUndoableMock extends Action implements Undoable { public ActionUndoableMock() { super(); } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { // } @Override public boolean canDo() { return false; } @Override public void undo() { // } @Override public void redo() { // } @Override public String getUndoName() { // TODO Auto-generated method stub return null; } } private class ActionMock extends Action { public ActionMock() { super(); } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { // } @Override public boolean canDo() { return false; } } private class ActionMock2 extends Action { public ActionMock2() { super(); } @Override public boolean cancelledBy(final Action action) { return action instanceof ActionMock; } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { // } @Override public boolean canDo() { return false; } } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/action/TestActivateInstrument.java000066400000000000000000000023651301161664300331510ustar00rootroot00000000000000package test.org.malai.action; import static org.junit.Assert.*; import org.malai.action.Action; import org.malai.action.library.ActivateInstrument; public class TestActivateInstrument extends TestInstrumentAction { @Override protected ActivateInstrument createAction() { return new ActivateInstrument(); } @SuppressWarnings("unused") @Override public void testConstructor() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Action act = new ActivateInstrument(); } @Override public void testDo() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final InstrumentMock ins = new InstrumentMock(); ins.setActivated(false); action.setInstrument(ins); action.doIt(); assertTrue(ins.isActivated()); } @Override public void testIsRegisterable() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { assertFalse(action.isRegisterable()); } @Override public void testHadEffect() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { assertFalse(action.hadEffect()); action.done(); assertTrue(action.hadEffect()); } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/action/TestInstrumentAction.java000066400000000000000000000023021301161664300326150ustar00rootroot00000000000000package test.org.malai.action; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; import org.junit.Test; import org.malai.action.library.InstrumentAction; import test.org.malai.HelperTest; public abstract class TestInstrumentAction extends TestAbstractAction { @Test @Override public void testCanDo() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { assertFalse(action.canDo()); action.setInstrument(new InstrumentMock()); assertTrue(action.canDo()); } @Test @Override public void testFlush() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { action.setInstrument(new InstrumentMock()); action.flush(); final Field field = HelperTest.getField(InstrumentAction.class, "instrument"); assertNull(field.get(action)); } @Test public void testGetSetInstrument() { final InstrumentMock ins = new InstrumentMock(); action.setInstrument(ins); assertEquals(ins, action.getInstrument()); } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/action/TestOpenWebPage.java000066400000000000000000000037621301161664300314560ustar00rootroot00000000000000package test.org.malai.action; import java.awt.Desktop; import static org.junit.Assert.*; import java.lang.reflect.Field; import java.net.URI; import org.malai.action.library.OpenWebPage; import test.org.malai.HelperTest; public class TestOpenWebPage extends TestAbstractAction { @Override protected OpenWebPage createAction() { return new OpenWebPage(); } @SuppressWarnings("unused") @Override public void testConstructor() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { new OpenWebPage(); } @Override public void testFlush() throws Exception { action.setUri(new URI("foo")); action.flush(); final Field act = HelperTest.getField(OpenWebPage.class, "uri"); assertNull(act.get(action)); } @Override public void testDo() throws Exception { action.setUri(new URI("http://www.google.com")); action.doIt(); } public void testDoBadURI() throws Exception { action.setUri(new URI("foo")); action.doIt(); } @Override public void testCanDo() throws Exception { if(HelperTest.isX11Set()) { assertFalse(action.canDo()); action.setUri(new URI("foo")); assertEquals(action.canDo(), Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)); action.setUri(null); assertFalse(action.canDo()); } } @Override public void testIsRegisterable() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { assertFalse(action.isRegisterable()); } @Override public void testHadEffect() throws Exception { if(HelperTest.isX11Set()) { assertFalse(action.hadEffect()); action.setUri(new URI("http://localhost")); assertFalse(action.hadEffect()); action.doIt(); action.done(); assertTrue(action.hadEffect()); } } public void testHadEffectBadURI() throws Exception { assertFalse(action.hadEffect()); action.setUri(new URI("foo")); assertFalse(action.hadEffect()); action.doIt(); action.done(); assertFalse(action.hadEffect()); } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/instrument/000077500000000000000000000000001301161664300265425ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/instrument/TestInstrument.java000066400000000000000000000025431301161664300324210ustar00rootroot00000000000000package test.org.malai.instrument; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; import org.junit.Test; import org.malai.instrument.Instrument; import org.malai.instrument.Interactor; public abstract class TestInstrument { protected T instrument; @Test public void testNotNoLink() { assertTrue(instrument.getNbInteractors()==0); if(!instrument.getInteractors().isEmpty()) { instrument.setActivated(true); assertTrue(instrument.getNbInteractors()>0); } } @Test public void testCreation() { assertFalse(instrument.isActivated()); assertFalse(instrument.isModified()); assertNotNull(instrument.getInteractors()); assertTrue(instrument.getInteractors().isEmpty()); } @Test public void testActivation() { instrument.setActivated(true); assertTrue(instrument.isActivated()); instrument.setActivated(false); assertFalse(instrument.isActivated()); } public Interactor getLink(final String nameClassLink) { Interactor interactor = null; final List interactors = instrument.getInteractors(); for(int i=0; i (ins, false, ActionMock2.class, InteractionMock.class) { @Override public void initAction() {// } @Override public boolean isConditionRespected() { return true; } }; ins.setActivated(true); interactor2.interactionStarts(interactor2.getInteraction()); assertTrue(ok[0]); assertNull(interactor.getAction()); ok[0] = false; ins = new MockInstrument(); interactor2 = new InteractorImpl(ins, false, ActionMock3.class, InteractionMock.class) { @Override public void initAction() {// } @Override public boolean isConditionRespected() { return true; } }; ins.setActivated(true); interactor2.interactionStarts(interactor2.getInteraction()); assertTrue(ok[0]); assertNull(interactor2.getAction()); } } class ActionMock2 extends ActionMock { // } class ActionMock3 extends ActionMock { ActionMock3(@SuppressWarnings("unused") final int foo) { // } } class MockInteractor extends InteractorImpl{ public boolean conditionRespected; public boolean mustAbort; public MockInteractor(final MockInstrument ins, final boolean exec, final Class clazzAction, final Class clazzInteraction) throws InstantiationException, IllegalAccessException { super(ins, exec, clazzAction, clazzInteraction); conditionRespected = false; mustAbort = false; } @Override public void initAction() { // } @Override public boolean isConditionRespected() { return conditionRespected; } @Override public boolean isInteractionMustBeAborted() { return mustAbort; } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/instrument/TestMockInstrument.java000066400000000000000000000021221301161664300332240ustar00rootroot00000000000000package test.org.malai.instrument; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import org.malai.instrument.InstrumentImpl; import org.malai.instrument.InteractorImpl; import test.org.malai.action.ActionMock; import test.org.malai.instrument.TestMockInstrument.MockInstrument; import test.org.malai.interaction.InteractionMock; public class TestMockInstrument extends TestInstrument { @Before public void setUp() throws Exception { instrument = new MockInstrument(); } @Test public void testHasLink() throws InstantiationException, IllegalAccessException { assertFalse(instrument.hasInteractors()); instrument.getInteractors().add(new MockInteractor(instrument, false, ActionMock.class, InteractionMock.class)); assertTrue(instrument.hasInteractors()); } public static class MockInstrument extends InstrumentImpl> { @Override protected void initialiseInteractors() throws InstantiationException, IllegalAccessException { // } } } TestMustBeUndoableActionException.java000066400000000000000000000012351301161664300360550ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/instrumentpackage test.org.malai.instrument; import static org.junit.Assert.*; import org.junit.Test; import org.malai.instrument.MustBeUndoableActionException; public class TestMustBeUndoableActionException { @Test public void testMustBeUndoableActionException() { @SuppressWarnings("unused") MustBeUndoableActionException ex = new MustBeUndoableActionException(null); ex = new MustBeUndoableActionException(Class.class); } @Test public void testToString() { MustBeUndoableActionException ex = new MustBeUndoableActionException(null); assertNotNull(ex.toString()); ex = new MustBeUndoableActionException(Class.class); assertNotNull(ex.toString()); } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/interaction/000077500000000000000000000000001301161664300266515ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/interaction/InteractionMock.java000066400000000000000000000004701301161664300326060ustar00rootroot00000000000000package test.org.malai.interaction; import org.malai.interaction.InteractionImpl; public class InteractionMock extends InteractionImpl { public InteractionMock() { super(); } @Override protected void initStateMachine() { // } @Override protected void processEvent(final Event event) { // } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/mapping/000077500000000000000000000000001301161664300257655ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/mapping/TestActiveArrayList.java000066400000000000000000000233031301161664300325370ustar00rootroot00000000000000package test.org.malai.mapping; import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Test; import org.malai.mapping.ActiveArrayList; import org.malai.mapping.IActiveList; import org.malai.mapping.MappingRegistry; import org.malai.mapping.SymmetricList2ListMapping; import static org.junit.Assert.*; public class TestActiveArrayList { protected IActiveList list; protected List list2; @Before public void setUp() { list = new ActiveArrayList<>(); list2 = new ArrayList<>(); MappingRegistry.REGISTRY.addMapping(new List2List(list, list2)); } @Test public void testMove() { try { list.move(0, 1); fail(); }catch(final IndexOutOfBoundsException e) { /* */ } assertEquals(0, list2.size()); list.add(new Integer(1)); list.move(0, 0); assertEquals(1, list2.size()); assertEquals(1, list2.get(0).intValue()); list.add(new Integer(2)); list.move(1, 0); assertEquals(2, list2.size()); assertEquals(2, list2.get(0).intValue()); assertEquals(1, list2.get(1).intValue()); list.move(0, 1); assertEquals(2, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(2, list2.get(1).intValue()); try { list.move(0, 10); fail(); }catch(final IndexOutOfBoundsException e) { /* */ } assertEquals(2, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(2, list2.get(1).intValue()); try { list.move(0, -1); fail(); }catch(final IndexOutOfBoundsException e) { /* */ } assertEquals(2, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(2, list2.get(1).intValue()); list.add(new Integer(3)); list.move(1, 2); assertEquals(3, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(3, list2.get(1).intValue()); assertEquals(2, list2.get(2).intValue()); list.move(0, 2); assertEquals(3, list2.size()); assertEquals(3, list2.get(0).intValue()); assertEquals(2, list2.get(1).intValue()); assertEquals(1, list2.get(2).intValue()); list.move(2, 0); assertEquals(3, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(3, list2.get(1).intValue()); assertEquals(2, list2.get(2).intValue()); list.add(new Integer(4)); list.move(1, 2); assertEquals(4, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(2, list2.get(1).intValue()); assertEquals(3, list2.get(2).intValue()); assertEquals(4, list2.get(3).intValue()); list.move(2, 1); assertEquals(4, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(3, list2.get(1).intValue()); assertEquals(2, list2.get(2).intValue()); assertEquals(4, list2.get(3).intValue()); list.move(0, 2); assertEquals(4, list2.size()); assertEquals(3, list2.get(0).intValue()); assertEquals(2, list2.get(1).intValue()); assertEquals(1, list2.get(2).intValue()); assertEquals(4, list2.get(3).intValue()); list.move(2, 0); assertEquals(4, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(3, list2.get(1).intValue()); assertEquals(2, list2.get(2).intValue()); assertEquals(4, list2.get(3).intValue()); } @Test public void testAdd1() { list.add(new Integer(1)); assertEquals(1, list2.size()); assertEquals(1, list2.get(0).intValue()); assertNotSame(list.get(0), list2.get(0)); list.add(new Integer(2)); assertEquals(2, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(2, list2.get(1).intValue()); assertNotSame(list.get(0), list2.get(0)); assertNotSame(list.get(1), list2.get(1)); } @Test public void testAdd2() { list.add(0, new Integer(1)); assertEquals(1, list2.size()); assertEquals(1, list2.get(0).intValue()); assertNotSame(list.get(0), list2.get(0)); list.add(1, new Integer(2)); assertEquals(2, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(2, list2.get(1).intValue()); assertNotSame(list.get(0), list2.get(0)); assertNotSame(list.get(1), list2.get(1)); list.add(0, new Integer(3)); assertEquals(3, list2.size()); assertEquals(3, list2.get(0).intValue()); assertEquals(1, list2.get(1).intValue()); assertEquals(2, list2.get(2).intValue()); assertNotSame(list.get(0), list2.get(0)); assertNotSame(list.get(1), list2.get(1)); assertNotSame(list.get(2), list2.get(2)); list.add(1, new Integer(4)); assertEquals(4, list2.size()); assertEquals(3, list2.get(0).intValue()); assertEquals(4, list2.get(1).intValue()); assertEquals(1, list2.get(2).intValue()); assertEquals(2, list2.get(3).intValue()); assertNotSame(list.get(0), list2.get(0)); assertNotSame(list.get(1), list2.get(1)); assertNotSame(list.get(2), list2.get(2)); assertNotSame(list.get(3), list2.get(3)); try { list.add(-1, new Integer(4)); fail(); }catch(final IndexOutOfBoundsException e) { /* */ } try { list.add(10, new Integer(4)); fail(); }catch(final IndexOutOfBoundsException e) { /* */ } } @Test public void testAddAll1() { final ArrayList list3 = new ArrayList<>(); list3.add(new Integer(0)); list3.add(new Integer(1)); list3.add(new Integer(2)); list3.add(new Integer(3)); list.addAll(list3); assertEquals(4, list2.size()); assertEquals(0, list2.get(0).intValue()); assertEquals(1, list2.get(1).intValue()); assertEquals(2, list2.get(2).intValue()); assertEquals(3, list2.get(3).intValue()); assertNotSame(list.get(0), list2.get(0)); assertNotSame(list.get(1), list2.get(1)); assertNotSame(list.get(2), list2.get(2)); assertNotSame(list.get(3), list2.get(3)); } @Test public void testAddAll2() { final ArrayList list3 = new ArrayList<>(); list3.add(new Integer(0)); list3.add(new Integer(1)); list3.add(new Integer(2)); list3.add(new Integer(3)); list.add(new Integer(10)); list.add(new Integer(11)); list.add(new Integer(12)); list.add(new Integer(13)); list.addAll(2, list3); assertEquals(8, list2.size()); assertEquals(10, list2.get(0).intValue()); assertEquals(11, list2.get(1).intValue()); assertEquals(0, list2.get(2).intValue()); assertEquals(1, list2.get(3).intValue()); assertEquals(2, list2.get(4).intValue()); assertEquals(3, list2.get(5).intValue()); assertEquals(12, list2.get(6).intValue()); assertEquals(13, list2.get(7).intValue()); assertNotSame(list.get(0), list2.get(0)); assertNotSame(list.get(1), list2.get(1)); assertNotSame(list.get(2), list2.get(2)); assertNotSame(list.get(3), list2.get(3)); assertNotSame(list.get(4), list2.get(4)); assertNotSame(list.get(5), list2.get(5)); assertNotSame(list.get(6), list2.get(6)); assertNotSame(list.get(7), list2.get(7)); } @Test public void testClear() { list.add(new Integer(10)); list.add(new Integer(11)); list.add(new Integer(12)); list.add(new Integer(13)); list.clear(); assertEquals(0, list2.size()); } @Test public void testRemove1() { assertFalse(list.remove(null)); assertEquals(0, list2.size()); assertFalse(list.remove(new Integer(0))); assertEquals(0, list2.size()); list.add(new Integer(1)); assertFalse(list.remove(new Integer(-1))); assertEquals(1, list2.size()); assertEquals(1, list2.get(0).intValue()); assertFalse(list.remove(new Integer(2))); assertEquals(1, list2.size()); assertEquals(1, list2.get(0).intValue()); assertTrue(list.remove(new Integer(1))); assertEquals(0, list2.size()); list.add(new Integer(1)); list.add(new Integer(2)); list.add(new Integer(3)); assertTrue(list.remove(new Integer(2))); assertEquals(2, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(3, list2.get(1).intValue()); list.add(new Integer(3)); assertTrue(list.remove(new Integer(3))); assertEquals(2, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(3, list2.get(1).intValue()); assertTrue(list.remove(new Integer(3))); assertEquals(1, list2.size()); assertEquals(1, list2.get(0).intValue()); } @Test public void testRemove2() { try { list.remove(-1); fail(); }catch(final IndexOutOfBoundsException e) { /* */ } assertEquals(0, list2.size()); try { list.remove(0); }catch(final IndexOutOfBoundsException e) { /* */ } assertEquals(0, list2.size()); list.add(new Integer(1)); list.remove(0); assertEquals(0, list2.size()); list.add(new Integer(1)); list.add(new Integer(2)); list.add(new Integer(3)); list.remove(1); assertEquals(2, list2.size()); assertEquals(1, list2.get(0).intValue()); assertEquals(3, list2.get(1).intValue()); list.remove(1); assertEquals(1, list2.size()); assertEquals(1, list2.get(0).intValue()); list.remove(0); assertEquals(0, list2.size()); } @Test public void testSet() { try { list.set(0, new Integer(1)); fail(); }catch(final IndexOutOfBoundsException e){ /* */ } list.add(new Integer(1)); try { list.set(-1, new Integer(1)); fail(); }catch(final IndexOutOfBoundsException e){ /* */ } try { list.set(1, new Integer(1)); fail(); }catch(final IndexOutOfBoundsException e){ /* */ } list.set(0, new Integer(0)); assertEquals(1, list2.size()); assertEquals(0, list2.get(0).intValue()); list.add(new Integer(1)); list.add(new Integer(2)); list.set(2, new Integer(3)); assertEquals(3, list2.size()); assertEquals(3, list2.get(2).intValue()); list.set(1, new Integer(4)); assertEquals(3, list2.size()); assertEquals(4, list2.get(1).intValue()); list.set(0, new Integer(5)); assertEquals(3, list2.size()); assertEquals(5, list2.get(0).intValue()); } } class List2List extends SymmetricList2ListMapping { public List2List(final List source, final List target) { super(source, target); } @Override protected Integer createTargetObject(final Object sourceObject) { return new Integer((Integer) sourceObject); } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/mapping/TestActiveUnary.java000066400000000000000000000031661301161664300317300ustar00rootroot00000000000000package test.org.malai.mapping; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.malai.mapping.ActiveUnary; import org.malai.mapping.IUnary; import org.malai.mapping.MappingRegistry; import org.malai.mapping.Unary2UnaryMapping; import static org.junit.Assert.*; public class TestActiveUnary { protected IUnary s2; protected IUnary s1; @Before public void setUp() { s1 = new ActiveUnary<>(); s2 = new ActiveUnary<>(); MappingRegistry.REGISTRY.addMapping(new S2S(s1, s2)); } @Test public void testConstructorValue() { s1 = new ActiveUnary<>(12); assertEquals(12, (int)s1.getValue()); } @Test public void testGetValue() { Integer integer = new Integer(1); s1.setValue(integer); assertEquals(integer, s1.getValue()); integer = new Integer(2); s1.setValue(integer); assertEquals(integer, s1.getValue()); } @Test public void testSetValue() { s1.setValue(new Integer(1)); assertEquals(s2.getValue(), s1.getValue()); assertEquals(1, s1.getValue().intValue()); s1.setValue(new Integer(2)); assertEquals(s2.getValue(), s1.getValue()); assertEquals(2, s1.getValue().intValue()); } } @Ignore class S2S extends Unary2UnaryMapping { public S2S(final IUnary source, final IUnary target) { super(source, target); } @Override public void onObjectModified(final Object object) { targetObject.setValue(new Integer(sourceObject.getValue())); } @Override public void onObjectReplaced(final IUnary object, final Object replacedObject) { targetObject.setValue(new Integer(sourceObject.getValue())); } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/mapping/TestList2ObjectMapping.java000066400000000000000000000044001301161664300331260ustar00rootroot00000000000000package test.org.malai.mapping; import static org.junit.Assert.*; import java.util.ArrayList; import java.util.List; import org.junit.Before; import org.junit.Test; import org.malai.mapping.IUnary; import org.malai.mapping.List2ObjectMapping; public class TestList2ObjectMapping { protected MockList2ObjectMapping map; protected List src; protected Object tgt; @Before public void setUp() { src = new ArrayList<>(); tgt = new Object(); map = new MockList2ObjectMapping(src, tgt); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullSrc() { new MockList2ObjectMapping(null, tgt); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullTgt() { new MockList2ObjectMapping(src, null); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullSrcTgt() { new MockList2ObjectMapping(src, null); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorSameSrcTgt() { new MockList2ObjectMapping(src, src); } @Test public void testGetSource() { assertEquals(src, map.getSource()); } @Test public void testGetTarget() { assertEquals(tgt, map.getTarget()); } @Test public void testClear() { map.clear(); assertNull(map.getSource()); assertNull(map.getTarget()); } public static class MockList2ObjectMapping extends List2ObjectMapping { public MockList2ObjectMapping(final List source, final Object target) { super(source, target); } @Override public void onObjectAdded(final Object list, final Object object, final int index) { // } @Override public void onObjectRemoved(final Object list, final Object object, final int index) { // } @Override public void onListCleaned(final Object list) { // } @Override public void onObjectMoved(final Object list, final Object object, final int srcIndex, final int targetIndex) { // } @Override public void onObjectReplaced(final IUnary object, final Object replacedObject) { // } @Override public void onObjectModified(final Object object) { // } @Override public void init() { // } } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/mapping/TestMappingRegistry.java000066400000000000000000000064721301161664300326250ustar00rootroot00000000000000package test.org.malai.mapping; import java.util.List; import javax.swing.JButton; import org.malai.mapping.ActiveArrayList; import org.malai.mapping.IMapping; import org.malai.mapping.IUnary; import org.malai.mapping.List2ObjectMapping; import org.malai.mapping.MappingRegistry; import static org.junit.Assert.*; public class TestMappingRegistry { public void testMappingAddedThenRemovedFromSourceObject() { final List list2 = new ActiveArrayList<>(); final JButton b2 = new JButton("b2"); final IMapping mapping = new MappingMock(list2, b2) { @Override public void onObjectAdded(final Object list, final Object object, final int index) { fail(); } }; MappingRegistry.REGISTRY.addMapping(mapping); MappingRegistry.REGISTRY.removeMappingsUsingSource(list2); assertNull(MappingRegistry.REGISTRY.getSourceFromTarget(b2, List.class)); list2.add(3.); } public void testMappingAddedThenRemovedFromSourceObjectClass() { final List list2 = new ActiveArrayList<>(); final JButton b2 = new JButton("b2"); final IMapping mapping = new MappingMock(list2, b2) { @Override public void onObjectAdded(final Object list, final Object object, final int index) { fail(); } }; MappingRegistry.REGISTRY.addMapping(mapping); MappingRegistry.REGISTRY.removeMappingsUsingSource(list2, mapping.getClass()); assertNull(MappingRegistry.REGISTRY.getSourceFromTarget(b2, List.class)); list2.add(3.); } public void testMappingAddedThenRemovedFromTargetObjectClass() { final List list2 = new ActiveArrayList<>(); final JButton b2 = new JButton("b2"); final IMapping mapping = new MappingMock(list2, b2) { @Override public void onObjectAdded(final Object list, final Object object, final int index) { fail(); } }; MappingRegistry.REGISTRY.addMapping(mapping); MappingRegistry.REGISTRY.removeMappingsUsingTarget(b2, mapping.getClass()); assertNull(MappingRegistry.REGISTRY.getSourceFromTarget(b2, List.class)); list2.add(3.); } public void testMappingAddedThenRemovedFromTargetObject() { final List list2 = new ActiveArrayList<>(); final JButton b2 = new JButton("b2"); final IMapping mapping = new MappingMock(list2, b2) { @Override public void onObjectAdded(final Object list, final Object object, final int index) { fail(); } }; MappingRegistry.REGISTRY.addMapping(mapping); MappingRegistry.REGISTRY.removeMappingsUsingTarget(b2); assertNull(MappingRegistry.REGISTRY.getSourceFromTarget(b2, List.class)); list2.add(3.); } class MappingMock extends List2ObjectMapping { MappingMock(final List source, final JButton target) { super(source, target); } @Override public void onObjectAdded(final Object list, final Object object, final int index) { // } @Override public void onObjectRemoved(final Object list, final Object object, final int index) { // } @Override public void onListCleaned(final Object list) { // } @Override public void onObjectMoved(final Object list, final Object object, final int srcIndex, final int targetIndex) { // } @Override public void onObjectReplaced(final IUnary object, final Object replacedObject) { // } @Override public void onObjectModified(final Object object) { // } @Override public void init() { // } } } TestObject2ObjectMapping.java000066400000000000000000000035231301161664300333470ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/mappingpackage test.org.malai.mapping; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import org.malai.mapping.Object2ObjectMapping; public class TestObject2ObjectMapping { protected MockObject2ObjectMapping map; protected Object src; protected Object tgt; @Before public void setUp() { src = new Object(); tgt = new Object(); map = new MockObject2ObjectMapping(src, tgt); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullSrc() { new MockObject2ObjectMapping(null, tgt); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullTgt() { new MockObject2ObjectMapping(src, null); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullSrcTgt() { new MockObject2ObjectMapping(src, null); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorSameSrcTgt() { new MockObject2ObjectMapping(src, src); } @Test public void testGetSource() { assertEquals(src, map.getSource()); } @Test public void testGetTarget() { assertEquals(tgt, map.getTarget()); } @Test public void testClear() { map.clear(); assertNull(map.getSource()); assertNull(map.getTarget()); } @Test public void testInit() { map.init(); assertTrue(map.modified); } @Test public void testInitWhenCleared() { map.clear(); map.init(); assertFalse(map.modified); } public static class MockObject2ObjectMapping extends Object2ObjectMapping { public boolean modified = false; public MockObject2ObjectMapping(final Object source, final Object target) { super(source, target); } @Override public void onObjectModified(final Object object) { modified = true; } } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/mapping/TestUnary2UnaryMapping.java000066400000000000000000000040761301161664300332120ustar00rootroot00000000000000package test.org.malai.mapping; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import org.malai.mapping.ActiveUnary; import org.malai.mapping.IUnary; import org.malai.mapping.Unary2UnaryMapping; public class TestUnary2UnaryMapping { protected MockUnary2UnaryMapping map; protected ActiveUnary src; protected ActiveUnary tgt; @Before public void setUp() { src = new ActiveUnary<>(); tgt = new ActiveUnary<>(); map = new MockUnary2UnaryMapping(src, tgt); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullSrc() { new MockUnary2UnaryMapping(null, tgt); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullTgt() { new MockUnary2UnaryMapping(src, null); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorNullSrcTgt() { new MockUnary2UnaryMapping(src, null); } @SuppressWarnings("unused") @Test(expected=IllegalArgumentException.class) public void testContructorSameSrcTgt() { new MockUnary2UnaryMapping(src, src); } @Test public void testGetSource() { assertEquals(src, map.getSource()); } @Test public void testGetTarget() { assertEquals(tgt, map.getTarget()); } @Test public void testClear() { map.clear(); assertNull(map.getSource()); assertNull(map.getTarget()); } @Test public void testInitWhenCleared() { map.clear(); map.init(); } @Test public void testInit() { map.init(); assertTrue(map.replaced); } public static class MockUnary2UnaryMapping extends Unary2UnaryMapping { public boolean replaced = false; public MockUnary2UnaryMapping(final IUnary source, final IUnary target) { super(source, target); } @Override public void onObjectReplaced(final IUnary object, final Object replacedObject) { replaced = true; assertEquals(object.getValue(), replacedObject); } @Override public void onObjectModified(final Object object) { // } } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/presentation/000077500000000000000000000000001301161664300270455ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/presentation/TestPresentation.java000066400000000000000000000057321301161664300332320ustar00rootroot00000000000000package test.org.malai.presentation; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; import org.malai.presentation.AbstractPresentation; import org.malai.presentation.ConcretePresentation; import org.malai.presentation.Presentation; import org.w3c.dom.Document; import org.w3c.dom.Element; public class TestPresentation { protected Presentation pres; protected MockPresAbs abs; protected MockPresConc conc; @Before public void setUp() throws Exception { abs = new MockPresAbs(); conc = new MockPresConc(); pres = new Presentation<>(abs, conc); } @Test public void testGetAbsPres() { assertEquals(abs, pres.getAbstractPresentation()); } @Test public void testGetConcPres() { assertEquals(conc, pres.getConcretePresentation()); } @Test public void testSetModified() { pres.setModified(true); assertTrue(conc.isModified()); assertTrue(abs.isModified()); pres.setModified(false); assertFalse(conc.isModified()); assertFalse(abs.isModified()); } @Test public void testIsModified() { pres.setModified(false); assertFalse(pres.isModified()); conc.isModif = true; assertTrue(pres.isModified()); conc.isModif = false; abs.isModif = true; assertTrue(pres.isModified()); conc.isModif = true; assertTrue(pres.isModified()); } @Test(expected=IllegalArgumentException.class) public void testConstructorAbsNull() { pres = new Presentation<>(null, new MockPresConc()); } @Test(expected=IllegalArgumentException.class) public void testConstructorConcNull() { pres = new Presentation<>(new MockPresAbs(), null); } @Test(expected=IllegalArgumentException.class) public void testConstructorAbsConcNull() { pres = new Presentation<>(null, null); } @Test public void testUpdate() { pres.update(); assertTrue(conc.updated); } @Test public void testReinit() { pres.reinit(); assertTrue(conc.reinit); assertTrue(abs.reinit); } public class MockPresAbs implements AbstractPresentation { public boolean isModif = false; public boolean reinit = false; @Override public void setModified(final boolean modified) { isModif = modified; } @Override public boolean isModified() { return isModif; } @Override public void reinit() { reinit = true; } } public class MockPresConc implements ConcretePresentation { public boolean isModif = false; public boolean updated = false; public boolean reinit = false; @Override public void save(final boolean generalPreferences, final String nsURI, final Document document, final Element root) { // } @Override public void load(final boolean generalPreferences, final String nsURI, final Element meta) { // } @Override public void setModified(final boolean modified) { isModif = modified; } @Override public boolean isModified() { return isModif; } @Override public void reinit() { reinit = true; } @Override public void update() { updated = true; } } } malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/undo/000077500000000000000000000000001301161664300252775ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.core/src/test/test/org/malai/undo/TestUndoCollector.java000066400000000000000000000264721301161664300315710ustar00rootroot00000000000000package test.org.malai.undo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; import java.util.Deque; import java.util.List; import org.junit.Before; import org.junit.Test; import org.malai.undo.EmptyUndoHandler; import org.malai.undo.UndoCollector; import org.malai.undo.UndoHandler; import org.malai.undo.Undoable; import test.org.malai.HelperTest; public class TestUndoCollector { boolean ok; @SuppressWarnings("unchecked") @Before public void setUp() throws Exception { ok = false; UndoCollector.INSTANCE.clear(); UndoCollector.INSTANCE.setSizeMax(10); final Field field = HelperTest.getField(UndoCollector.class, "handlers"); final List list = (List)field.get(UndoCollector.INSTANCE); list.clear(); } @Test public void testRedo_withUndoDone_withGlobalUndoable() { final UndoHandler handler = new EmptyUndoHandler() { @Override public void onUndoableRedo(final Undoable undoable) { ok = true; } }; ok = false; UndoCollector.INSTANCE.addHandler(handler); UndoCollector.INSTANCE.add(new MockUndoable(), null); UndoCollector.INSTANCE.undo(); UndoCollector.INSTANCE.redo(); assertTrue(ok); } @Test public void testRedo_withUndoDone_withUndoable() { final UndoHandler handler = new EmptyUndoHandler() { @Override public void onUndoableRedo(final Undoable undoable) { ok = true; } }; ok = false; UndoCollector.INSTANCE.add(new MockUndoable(), handler); UndoCollector.INSTANCE.undo(); UndoCollector.INSTANCE.redo(); assertTrue(ok); } @Test public void testRedo_whenRedoEmpty() { final UndoHandler handler = new EmptyUndoHandler() { @Override public void onUndoableRedo(final Undoable undoable) { ok = false; } }; ok = true; UndoCollector.INSTANCE.addHandler(handler); UndoCollector.INSTANCE.redo(); assertTrue(ok); } @Test public void testUndoCall_undo() { final MockUndoable undoable = new MockUndoable() { @Override public void undo() { ok = true; } }; UndoCollector.INSTANCE.add(undoable, null); UndoCollector.INSTANCE.undo(); assertTrue(ok); } @Test public void testUndo_whenUndoEmpty() { final UndoHandler handler = new EmptyUndoHandler() { @Override public void onUndoableUndo(final Undoable undoable) { ok = false; } }; ok = true; UndoCollector.INSTANCE.addHandler(handler); UndoCollector.INSTANCE.undo(); assertTrue(ok); } @Test public void testRedoCall_redo() { final MockUndoable undoable = new MockUndoable() { @Override public void redo() { ok = true; } }; final UndoHandler handler = new EmptyUndoHandler() { @Override public void onUndoableUndo(final Undoable u) { assertEquals(undoable, u); } }; UndoCollector.INSTANCE.add(undoable, handler); UndoCollector.INSTANCE.undo(); UndoCollector.INSTANCE.redo(); assertTrue(ok); assertEquals(undoable, UndoCollector.INSTANCE.getLastUndo()); UndoCollector.INSTANCE.undo(); } @Test public void testAddUndoableFollowedByUndo_withUndoHandler() { UndoCollector.INSTANCE.setSizeMax(5); ok = false; UndoCollector.INSTANCE.add(new MockUndoable(), new UndoHandler() { @Override public void onUndoableUndo(final Undoable undoable) { ok = true; } @Override public void onUndoableRedo(final Undoable undoable) { throw new IllegalArgumentException(); } @Override public void onUndoableCleared() { throw new IllegalArgumentException(); } @Override public void onUndoableAdded(final Undoable undoable) { throw new IllegalArgumentException(); } }); UndoCollector.INSTANCE.undo(); assertTrue(ok); } @Test public void testAddUndoableFollowedByUndo_withDefaultndoHandler() { UndoCollector.INSTANCE.setSizeMax(5); final UndoHandler handler = new EmptyUndoHandler() { @Override public void onUndoableUndo(final Undoable undoable) { ok = true; } }; ok = false; UndoCollector.INSTANCE.addHandler(handler); UndoCollector.INSTANCE.add(new MockUndoable(), null); UndoCollector.INSTANCE.undo(); assertTrue(ok); } @Test public void testAddCall_onUndoableAdded() { UndoCollector.INSTANCE.addHandler(new EmptyUndoHandler() { @Override public void onUndoableAdded(final Undoable undoable) { ok = true; } }); UndoCollector.INSTANCE.add(new MockUndoable(), null); assertTrue(ok); } @Test public void testAddUndoable_with0SizeUndoable() { UndoCollector.INSTANCE.setSizeMax(0); UndoCollector.INSTANCE.add(new MockUndoable(), null); assertTrue(UndoCollector.INSTANCE.getUndo().isEmpty()); assertTrue(UndoCollector.INSTANCE.getRedo().isEmpty()); } @Test public void testAddUndoable_withNullUndoable() { UndoCollector.INSTANCE.setSizeMax(5); UndoCollector.INSTANCE.add(null, null); assertTrue(UndoCollector.INSTANCE.getUndo().isEmpty()); assertTrue(UndoCollector.INSTANCE.getRedo().isEmpty()); } @Test public void testAddUndoable_withLimitedUndoSize() { final Undoable undoable1 = new MockUndoable(); final Undoable undoable2 = new MockUndoable(); UndoCollector.INSTANCE.setSizeMax(1); UndoCollector.INSTANCE.add(undoable1, null); UndoCollector.INSTANCE.add(undoable2, null); assertEquals(1, UndoCollector.INSTANCE.getUndo().size()); assertEquals(undoable2, UndoCollector.INSTANCE.getUndo().getFirst()); } @Test public void testGetRedos() { assertNotNull(UndoCollector.INSTANCE.getRedo()); } @Test public void testGetUndos() { assertNotNull(UndoCollector.INSTANCE.getUndo()); } @Test public void testSizeMaxMutatorsUndoableRemoved() { UndoCollector.INSTANCE.setSizeMax(5); UndoCollector.INSTANCE.add(new MockUndoable(), null); assertNotNull(UndoCollector.INSTANCE.getLastUndo()); UndoCollector.INSTANCE.setSizeMax(0); assertNull(UndoCollector.INSTANCE.getLastUndo()); } @Test public void testSizeMaxMutatorsSize() { UndoCollector.INSTANCE.setSizeMax(21); assertEquals(21, UndoCollector.INSTANCE.getSizeMax()); UndoCollector.INSTANCE.setSizeMax(32); assertEquals(32, UndoCollector.INSTANCE.getSizeMax()); UndoCollector.INSTANCE.setSizeMax(9); assertEquals(9, UndoCollector.INSTANCE.getSizeMax()); UndoCollector.INSTANCE.setSizeMax(0); assertEquals(0, UndoCollector.INSTANCE.getSizeMax()); UndoCollector.INSTANCE.setSizeMax(5); assertEquals(5, UndoCollector.INSTANCE.getSizeMax()); UndoCollector.INSTANCE.setSizeMax(-1); assertEquals(5, UndoCollector.INSTANCE.getSizeMax()); } @Test public void testGetLastRedo() { final Undoable undoable = new MockUndoable(); assertNull(UndoCollector.INSTANCE.getLastRedo()); UndoCollector.INSTANCE.add(undoable, null); assertNull(UndoCollector.INSTANCE.getLastRedo()); UndoCollector.INSTANCE.undo(); assertEquals(undoable, UndoCollector.INSTANCE.getLastRedo()); } @Test public void testGetLastUndo() { final Undoable undoable = new MockUndoable(); assertNull(UndoCollector.INSTANCE.getLastUndo()); UndoCollector.INSTANCE.add(undoable, null); assertEquals(undoable, UndoCollector.INSTANCE.getLastUndo()); } @Test public void testGetLastUndoMessage() { assertNull(UndoCollector.INSTANCE.getLastUndoMessage()); UndoCollector.INSTANCE.add(new MockUndoable("undoredomsg"), null); assertEquals("undoredomsg", UndoCollector.INSTANCE.getLastUndoMessage()); } @Test public void testGetLastRedoMessage() { assertNull(UndoCollector.INSTANCE.getLastRedoMessage()); UndoCollector.INSTANCE.add(new MockUndoable("undoredomsg"), null); assertNull(UndoCollector.INSTANCE.getLastRedoMessage()); UndoCollector.INSTANCE.undo(); assertEquals("undoredomsg", UndoCollector.INSTANCE.getLastRedoMessage()); } @Test public void testClear() throws SecurityException, IllegalArgumentException { UndoCollector.INSTANCE.add(new MockUndoable(), null); UndoCollector.INSTANCE.add(new MockUndoable(), null); UndoCollector.INSTANCE.undo(); UndoCollector.INSTANCE.clear(); assertNull(UndoCollector.INSTANCE.getLastRedo()); assertNull(UndoCollector.INSTANCE.getLastUndo()); } @Test public void testClearLaunch_UndoableCleaned() { final UndoHandler handler = new EmptyUndoHandler() { @Override public void onUndoableCleared() { ok = true; } }; UndoCollector.INSTANCE.addHandler(handler); UndoCollector.INSTANCE.clear(); assertTrue(ok); } @Test public void testClearLaunchedHandlersCleaned() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final UndoHandler handler1 = new EmptyUndoHandler() { @Override public void onUndoableCleared() { ok = true; } }; final UndoHandler handler2 = new EmptyUndoHandler() { @Override public void onUndoableCleared() { ok = true; } }; UndoCollector.INSTANCE.add(new MockUndoable(), handler1); UndoCollector.INSTANCE.add(new MockUndoable(), handler2); UndoCollector.INSTANCE.undo(); UndoCollector.INSTANCE.clear(); assertTrue(((Deque)HelperTest.getField(UndoCollector.class, "undoHandlers").get(UndoCollector.INSTANCE)).isEmpty()); assertTrue(((Deque)HelperTest.getField(UndoCollector.class, "redoHandlers").get(UndoCollector.INSTANCE)).isEmpty()); } @SuppressWarnings("unchecked") @Test public void testAddHandler() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final UndoHandler handler1 = new EmptyUndoHandler(); final UndoHandler handler2 = new EmptyUndoHandler(); UndoCollector.INSTANCE.addHandler(null); final Field field = HelperTest.getField(UndoCollector.class, "handlers"); final List list = (List)field.get(UndoCollector.INSTANCE); assertTrue(list.isEmpty()); UndoCollector.INSTANCE.addHandler(handler1); assertEquals(handler1, list.get(0)); UndoCollector.INSTANCE.addHandler(handler2); assertEquals(handler1, list.get(0)); assertEquals(handler2, list.get(1)); } @SuppressWarnings("unchecked") @Test public void testremoveHandler() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final UndoHandler handler1 = new EmptyUndoHandler(); final UndoHandler handler2 = new EmptyUndoHandler(); UndoCollector.INSTANCE.removeHandler(null); final Field field = HelperTest.getField(UndoCollector.class, "handlers"); final List list = (List)field.get(UndoCollector.INSTANCE); assertTrue(list.isEmpty()); UndoCollector.INSTANCE.addHandler(handler1); assertEquals(handler1, list.get(0)); UndoCollector.INSTANCE.removeHandler(null); assertEquals(handler1, list.get(0)); UndoCollector.INSTANCE.removeHandler(handler1); assertTrue(list.isEmpty()); UndoCollector.INSTANCE.addHandler(handler1); UndoCollector.INSTANCE.addHandler(handler2); UndoCollector.INSTANCE.removeHandler(null); assertEquals(handler1, list.get(0)); assertEquals(handler2, list.get(1)); UndoCollector.INSTANCE.removeHandler(handler1); assertEquals(handler2, list.get(0)); UndoCollector.INSTANCE.removeHandler(handler2); assertTrue(list.isEmpty()); UndoCollector.INSTANCE.removeHandler(handler2); assertTrue(list.isEmpty()); } public class MockUndoable implements Undoable { protected String undoMsg; public MockUndoable() { this(""); } public MockUndoable(final String undoMsg) { super(); this.undoMsg = undoMsg; } @Override public void undo() {// } @Override public void redo() {// } @Override public String getUndoName() { return undoMsg; } } } malai-2.0+ds1/malai-core/org.malai.javafx/000077500000000000000000000000001301161664300202625ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/.gitignore000066400000000000000000000000511301161664300222460ustar00rootroot00000000000000/target /.settings /.classpath /.project malai-2.0+ds1/malai-core/org.malai.javafx/history.txt000066400000000000000000000000371301161664300225240ustar00rootroot00000000000000Version 2.0 Initial release. malai-2.0+ds1/malai-core/org.malai.javafx/pom.xml000066400000000000000000000065261301161664300216100ustar00rootroot00000000000000 4.0.0 org.malai malai.javafx 2.0 jar malai.javafx :: Malai JavaFX component UTF-8 src/main src/resources/ maven-assembly-plugin 2.4 src/assembly/assemblySrc.xml src/assembly/assemblyBin.xml make-assembly package single org.apache.maven.plugins maven-compiler-plugin 3.1 1.8 1.8 UTF-8 org.apache.felix maven-bundle-plugin 3.0.1 true methods 2 org.malai.* org.apache.maven.plugins maven-surefire-plugin 2.19.1 net.java.javafx javafx 2.0 system ${project.basedir}/lib/jfxrt.jar org.malai malai.core ${project.version} org.malai malai.core ${project.version} test-jar test mavenInriaSnapshot http://maven.inria.fr-snapshots http://maven.inria.fr/artifactory/malai-public-snapshot mavenInriaRelease http://maven.inria.fr-releases http://maven.inria.fr/artifactory/malai-public-release malai-2.0+ds1/malai-core/org.malai.javafx/src/000077500000000000000000000000001301161664300210515ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/assembly/000077500000000000000000000000001301161664300226705ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/assembly/assemblyBin.xml000066400000000000000000000016751301161664300256730ustar00rootroot00000000000000 bin zip ${project.build.directory} / ${project.artifactId}-${project.version}.jar true ${project.basedir} / license* history.txt true malai-2.0+ds1/malai-core/org.malai.javafx/src/assembly/assemblySrc.xml000066400000000000000000000015271301161664300257060ustar00rootroot00000000000000 src zip ${project.basedir} src/ compile history.txt license* pom.xml .classpath .gitignore .project .settings/ true malai-2.0+ds1/malai-core/org.malai.javafx/src/main/000077500000000000000000000000001301161664300217755ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/000077500000000000000000000000001301161664300225645ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/000077500000000000000000000000001301161664300236475ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/000077500000000000000000000000001301161664300251265ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/action/000077500000000000000000000000001301161664300264035ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/action/library/000077500000000000000000000000001301161664300300475ustar00rootroot00000000000000ActivateInactivateInstruments.java000066400000000000000000000056611301161664300366670ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/action/library/* * This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/ package org.malai.javafx.action.library; import java.util.ArrayList; import java.util.List; import org.malai.action.Action; import org.malai.javafx.instrument.JfxInstrument; /** * This instrument activates and inactivates instruments.
*
* @author Arnaud Blouin * @since 2.0 */ public class ActivateInactivateInstruments extends Action { /** The instruments to activate. */ protected List insActivate; /** The instrument to desactivate. */ protected List insInactivate; /** Defines the activations must be performed before the inactivations. */ protected boolean activateFirst; /** * Creates and initialises the instrument. * By default instruments are not hidden and activation is performed first. * @since 0.1 */ public ActivateInactivateInstruments() { super(); activateFirst = true; } @Override public void flush() { super.flush(); if(insActivate!=null) insActivate.clear(); if(insInactivate!=null) insInactivate.clear(); } @Override protected void doActionBody() { if(activateFirst) { activate(); deactivate(); } else { deactivate(); activate(); } } protected void deactivate() { if(insInactivate!=null) insInactivate.forEach(ins -> ins.setActivated(false)); } protected void activate() { if(insActivate!=null) insActivate.forEach(ins -> ins.setActivated(true)); } /** * Adds an instrument to activate. * @param ins The instrument to activate. * @since 0.1 */ public void addInstrumentToActivate(final JfxInstrument ins) { if(ins!=null) { if(insActivate==null) insActivate = new ArrayList<>(); insActivate.add(ins); } } /** * Adds an instrument to inactivate. * @param ins The instrument to inactivate. * @since 0.1 */ public void addInstrumentToInactivate(final JfxInstrument ins) { if(ins!=null) { if(insInactivate==null) insInactivate = new ArrayList<>(); insInactivate.add(ins); } } @Override public boolean canDo() { return insActivate!=null || insInactivate!=null; } /** * @return False. Action ActivateInactivateInstruments cannot be registered. */ @Override public boolean isRegisterable() { return false; } /** * @param activateFirst True: the activations will be performed before the inactivations. * @since 0.2 */ public void setActivateFirst(final boolean activateFirst) { this.activateFirst = activateFirst; } } malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/action/library/MoveCamera.java000066400000000000000000000033371301161664300327370ustar00rootroot00000000000000package org.malai.javafx.action.library; import org.malai.action.library.PositionAction; import javafx.scene.control.ScrollPane; /** * This action moves a camera by moving the scroll bars of a pane.
* The use of this action can be made when an object has a lot of properties which modification * follow the same process. Thus, a same action can be used to modify all the properties. To do so, * a enumeration of the properties can be defined and used into the action to specify which property * will be modified by the current action instance.
* This file is part of Malai
* Copyright (c) 2005-2014 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under the terms of the GNU * General Public License as published by the Free Software Foundation; either version 2 of the * License, or any later version.
*
* Malai is distributed without any warranty; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* @author Arnaud Blouin * @since 2.0 */ public class MoveCamera extends PositionAction { /** The scroll panel to modify. */ protected ScrollPane scrollPane; /** * Creates the action. */ public MoveCamera() { super(); } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { scrollPane.setHvalue(px); scrollPane.setVvalue(py); } @Override public boolean canDo() { return super.canDo() && scrollPane != null; } /** * Sets the scroll panel to modify. * @param scrollp The scroll panel to modify. */ public void setScrollPane(final ScrollPane scrollp) { scrollPane = scrollp; } } OpenWebPageJFX.java000066400000000000000000000033131301161664300333370ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/action/librarypackage org.malai.javafx.action.library; import org.malai.action.Action; import java.awt.*; import java.io.IOException; import java.net.URI; /** * This action opens an URI in the default browser.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 08/11/2011
* @author Arnaud BLOUIN * @version 0.2 * @since 0.2 */ public class OpenWebPageJFX extends Action { /** The URI to open. */ protected URI uri; private boolean browsed; /** * Creates the action. * @since 0.2 */ public OpenWebPageJFX() { super(); browsed = false; } @Override public boolean isRegisterable() { return false; } @Override public void flush() { uri = null; } @Override protected void doActionBody() { new Thread(() -> { try { Desktop.getDesktop().browse(uri); browsed = true; }catch(IOException e) { browsed = false; } }).start(); } @Override public boolean canDo() { return uri!=null && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE); } @Override public boolean hadEffect() { return super.hadEffect() && browsed; } /** * @param uri The URI to open. * @since 0.2 */ public void setUri(final URI uri) { this.uri = uri; } } malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/action/library/ShowNode.java000066400000000000000000000024651301161664300324470ustar00rootroot00000000000000/* *
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
*/ package org.malai.javafx.action.library; import javafx.scene.Node; /** * This action shows or hides a JComponent.
* @author Arnaud BLOUIN * @since 2.0 */ public class ShowNode extends WidgetAction { /** Defines if the component must be shown or hidden. */ protected boolean visible; /** * Creates the action. */ public ShowNode() { super(); } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { widget.setVisible(visible); } @Override public boolean canDo() { return super.canDo() && widget.isVisible()!=visible; } /** * @param visible Defines if the component must be shown or hidden. */ public void setVisible(final boolean visible) { this.visible = visible; } } malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/action/library/ShowStage.java000066400000000000000000000025301301161664300326160ustar00rootroot00000000000000/* *
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
*/ package org.malai.javafx.action.library; import javafx.stage.Stage; /** * This action shows or hides a window.
* @author Arnaud BLOUIN * @since 2.0 */ public class ShowStage extends WidgetAction { /** Defines if the component must be shown or hidden. */ protected boolean visible; /** * Creates the action. */ public ShowStage() { super(); } @Override public boolean isRegisterable() { return false; } @Override protected void doActionBody() { if(visible) widget.show(); else widget.hide(); } // @Override // public boolean canDo() { // return super.canDo() && widget.isShowing()!=visible; // } /** * @param visible Defines if the component must be shown or hidden. */ public void setVisible(final boolean visible) { this.visible = visible; } } malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/action/library/WidgetAction.java000066400000000000000000000022641301161664300332770ustar00rootroot00000000000000/* * This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/ package org.malai.javafx.action.library; import org.malai.action.Action; /** * Defines an abstract action that concerns a widget. *
* @author Arnaud BLOUIN * @version 2.0 */ public abstract class WidgetAction extends Action { /** The component concerned by the action. */ protected T widget; /** * Creates the action. */ public WidgetAction() { super(); } @Override public boolean canDo() { return widget!=null; } /** * @param n The component concerned by the action. * @since 0.2 */ public void setWidget(final T n) { this.widget = n; } @Override public void flush() { super.flush(); widget = null; } } malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/000077500000000000000000000000001301161664300273365ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/JfxInstrument.java000066400000000000000000000020011301161664300330120ustar00rootroot00000000000000package org.malai.javafx.instrument; import org.malai.instrument.InstrumentImpl; import org.malai.javafx.interaction.JfxInteraction; /** * Base of an instrument for JavaFX applications.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 2014-09-19 * @version 2.0 */ public abstract class JfxInstrument extends InstrumentImpl>{ /** * Creates the instrument. */ public JfxInstrument() { super(); } } malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/JfxInteractor.java000066400000000000000000000073031301161664300327660ustar00rootroot00000000000000package org.malai.javafx.instrument; import java.util.Arrays; import java.util.List; import javafx.scene.Node; import org.malai.action.Action; import org.malai.instrument.InteractorImpl; import org.malai.javafx.interaction.JfxInteraction; /** * Base of an interactor for JavaFX applications.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @date 2014-09-19 * @version 2.0 */ public abstract class JfxInteractor extends InteractorImpl { /** * Creates an interactor. This constructor must initialise the interaction. The interactor is (de-)activated if the given * instrument is (de-)activated. * @param ins The instrument that contains the interactor. * @param exec Specifies if the action must be execute or update on each evolution of the interaction. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param clazzInteraction The type of the interaction that will be created. Used to instantiate the interaction by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public JfxInteractor(N ins, boolean exec, Class clazzAction, Class clazzInteraction, List widgets) throws InstantiationException, IllegalAccessException { super(ins, exec, clazzAction, clazzInteraction); interaction.registerToNodes(widgets); } /** * Creates an interactor. This constructor must initialise the interaction. The interactor is (de-)activated if the given * instrument is (de-)activated. * @param ins The instrument that contains the interactor. * @param exec Specifies if the action must be execute or update on each evolution of the interaction. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param clazzInteraction The type of the interaction that will be created. Used to instantiate the interaction by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public JfxInteractor(N ins, boolean exec, Class clazzAction, Class clazzInteraction, Node... widgets) throws InstantiationException, IllegalAccessException { this(ins, exec, clazzAction, clazzInteraction, Arrays.asList(widgets)); } @Override public boolean isConditionRespected() { return true; } } JfxMenuItemInteractor.java000066400000000000000000000051601301161664300343520ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrumentpackage org.malai.javafx.instrument; import javafx.scene.control.MenuItem; import org.malai.action.Action; import org.malai.javafx.interaction.library.MenuItemInteraction; import java.util.Collections; /** * Base of an interactor for JavaFX applications.
*
* This file is part of libMalai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* libMalan is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version.
*
* libMalan is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* @author Arnaud BLOUIN * @version 2.0 */ public abstract class JfxMenuItemInteractor
, N extends JfxInstrument> extends JfxInteractor { /** The menu item that will be uses to create the action. */ protected MenuItem menuItem; /** * Creates an interactor. This constructor must initialise the interaction. The interactor is (de-)activated if the given * instrument is (de-)activated. * @param ins The instrument that contains the interactor. * @param exec Specifies if the action must be execute or update on each evolution of the interaction. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param clazzInteraction The type of the interaction that will be created. Used to instantiate the interaction by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widget The menu item used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public JfxMenuItemInteractor(N ins, boolean exec, Class clazzAction, Class clazzInteraction, MenuItem widget) throws InstantiationException, IllegalAccessException { super(ins, exec, clazzAction, clazzInteraction); if(widget==null) throw new IllegalArgumentException(); menuItem = widget; interaction.registerToMenuItems(Collections.singletonList(widget)); } @Override public boolean isConditionRespected() { return interaction.getWidget()==menuItem; } } malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/library/000077500000000000000000000000001301161664300310025ustar00rootroot00000000000000ButtonInteractor.java000066400000000000000000000052601301161664300350770ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/library/* * This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/ package org.malai.javafx.instrument.library; import java.util.List; import javafx.scene.Node; import org.malai.action.Action; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxInteractor; import org.malai.javafx.interaction.library.ButtonPressed; /** * An interactor using a JFX button interaction. * @param
The action to produce. * @param The instrument. */ public abstract class ButtonInteractor extends JfxInteractor { /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public ButtonInteractor(I ins, Class clazzAction, List widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, ButtonPressed.class, widgets); } /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public ButtonInteractor(I ins, Class clazzAction, Node... widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, ButtonPressed.class, widgets); } } CheckboxInteractor.java000066400000000000000000000052541301161664300353550ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/library/* * This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/ package org.malai.javafx.instrument.library; import java.util.List; import javafx.scene.Node; import org.malai.action.Action; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxInteractor; import org.malai.javafx.interaction.library.BoxChecked; /** * An interactor using a JFX checkbox interaction. * @param
The action to produce. * @param The instrument. */ public abstract class CheckboxInteractor extends JfxInteractor { /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public CheckboxInteractor(I ins, Class clazzAction, List widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, BoxChecked.class, widgets); } /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public CheckboxInteractor(I ins, Class clazzAction, Node... widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, BoxChecked.class, widgets); } } ColorPickerInteractor.java000066400000000000000000000052751301161664300360460ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/library/* * This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/ package org.malai.javafx.instrument.library; import java.util.List; import javafx.scene.Node; import org.malai.action.Action; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxInteractor; import org.malai.javafx.interaction.library.ColorPicked; /** * An interactor using a JFX color picker interaction. * @param
The action to produce. * @param The instrument. */ public abstract class ColorPickerInteractor extends JfxInteractor { /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public ColorPickerInteractor(I ins, Class clazzAction, List widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, ColorPicked.class, widgets); } /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public ColorPickerInteractor(I ins, Class clazzAction, Node... widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, ColorPicked.class, widgets); } } ComboBoxInteractor.java000066400000000000000000000053051301161664300353340ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/library/* * This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/ package org.malai.javafx.instrument.library; import java.util.List; import javafx.scene.Node; import org.malai.action.Action; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxInteractor; import org.malai.javafx.interaction.library.ComboBoxSelected; /** * An interactor using a JFX combo box interaction. * @param
The action to produce. * @param The instrument. */ public abstract class ComboBoxInteractor extends JfxInteractor { /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public ComboBoxInteractor(I ins, Class clazzAction, List widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, ComboBoxSelected.class, widgets); } /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public ComboBoxInteractor(I ins, Class clazzAction, Node... widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, ComboBoxSelected.class, widgets); } } MenuItem2OpenWebPageInteractor.java000066400000000000000000000040101301161664300374760ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/librarypackage org.malai.javafx.instrument.library; import javafx.scene.control.MenuItem; import org.malai.javafx.action.library.OpenWebPageJFX; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxMenuItemInteractor; import org.malai.javafx.interaction.library.MenuItemPressed; import java.net.URI; /** * An interactor that opens a URL using a menu item.
*
* This file is part of Malai.
* Copyright (c) 2005-2016 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2016/05/22
* @author Arnaud BLOUIN * @since 2.0 */ public class MenuItem2OpenWebPageInteractor extends JfxMenuItemInteractor { /** The URI to open. */ protected URI uri; /** * Creates the interactor. * @param ins The instrument that will contain the interactor. * @param menuItem he menu item that will be uses to create the action. * @param uri The URI to open. * @throws IllegalArgumentException If one of the given parameters is null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @since 2.0 */ public MenuItem2OpenWebPageInteractor(final JfxInstrument ins, final MenuItem menuItem, final URI uri) throws InstantiationException, IllegalAccessException { super(ins, false, OpenWebPageJFX.class, MenuItemPressed.class, menuItem); if(uri==null) throw new IllegalArgumentException(); this.uri = uri; } @Override public void initAction() { action.setUri(uri); } } MenuItem2ShowLazyStage.java000066400000000000000000000044531301161664300360660ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/librarypackage org.malai.javafx.instrument.library; import javafx.scene.control.MenuItem; import javafx.stage.Stage; import org.malai.javafx.action.library.ShowStage; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxMenuItemInteractor; import org.malai.javafx.interaction.library.MenuItemPressed; import java.util.function.Supplier; /** * An interactor that opens a URL using a menu item.
*
* This file is part of Malai.
* Copyright (c) 2005-2016 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2016/05/22
* @author Arnaud BLOUIN * @since 2.0 */ public class MenuItem2ShowLazyStage extends JfxMenuItemInteractor { protected Supplier stageToShowLazy; protected boolean show; /** * Creates the interactor. * @param ins The instrument that will contain the interactor. * @param menuItem he menu item that will be uses to create the action. * @param stageLazy The stage to show or hide (the creation of the stage can be postponed at the execution of the action). * @throws IllegalArgumentException If one of the given parameters is null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @since 2.0 */ public MenuItem2ShowLazyStage(final JfxInstrument ins, final MenuItem menuItem, final Supplier stageLazy, final boolean toshow) throws InstantiationException, IllegalAccessException { super(ins, false, ShowStage.class, MenuItemPressed.class, menuItem); if(stageLazy==null) throw new IllegalArgumentException(); stageToShowLazy = stageLazy; show = toshow; } @Override public void initAction() { System.out.println(stageToShowLazy.get()); action.setWidget(stageToShowLazy.get()); action.setVisible(show); } } MenuItem2ShowNode.java000066400000000000000000000040761301161664300350510ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/librarypackage org.malai.javafx.instrument.library; import javafx.scene.Node; import javafx.scene.control.MenuItem; import org.malai.javafx.action.library.ShowNode; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxMenuItemInteractor; import org.malai.javafx.interaction.library.MenuItemPressed; /** * An interactor that opens a URL using a menu item.
*
* This file is part of Malai.
* Copyright (c) 2005-2016 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2016/05/22
* @author Arnaud BLOUIN * @since 2.0 */ public class MenuItem2ShowNode extends JfxMenuItemInteractor { protected Node nodeToShow; protected boolean show; /** * Creates the interactor. * @param ins The instrument that will contain the interactor. * @param menuItem he menu item that will be uses to create the action. * @param node The node to show or hide * @throws IllegalArgumentException If one of the given parameters is null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @since 2.0 */ public MenuItem2ShowNode(final JfxInstrument ins, final MenuItem menuItem, final Node node, final boolean toshow) throws InstantiationException, IllegalAccessException { super(ins, false, ShowNode.class, MenuItemPressed.class, menuItem); if(node==null) throw new IllegalArgumentException(); nodeToShow = node; show = toshow; } @Override public void initAction() { action.setWidget(nodeToShow); action.setVisible(show); } } MenuItem2ShowStage.java000066400000000000000000000041161301161664300352220ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/librarypackage org.malai.javafx.instrument.library; import javafx.scene.control.MenuItem; import javafx.stage.Stage; import org.malai.javafx.action.library.ShowStage; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxMenuItemInteractor; import org.malai.javafx.interaction.library.MenuItemPressed; /** * An interactor that opens a URL using a menu item.
*
* This file is part of Malai.
* Copyright (c) 2005-2016 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2016/05/22
* @author Arnaud BLOUIN * @since 2.0 */ public class MenuItem2ShowStage extends JfxMenuItemInteractor { protected Stage stageToShow; protected boolean show; /** * Creates the interactor. * @param ins The instrument that will contain the interactor. * @param menuItem he menu item that will be uses to create the action. * @param stage The stage to show or hide * @throws IllegalArgumentException If one of the given parameters is null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @since 2.0 */ public MenuItem2ShowStage(final JfxInstrument ins, final MenuItem menuItem, final Stage stage, final boolean toshow) throws InstantiationException, IllegalAccessException { super(ins, false, ShowStage.class, MenuItemPressed.class, menuItem); if(stage==null) throw new IllegalArgumentException(); stageToShow = stage; show = toshow; } @Override public void initAction() { action.setWidget(stageToShow); action.setVisible(show); } } MenuItemInteractor.java000066400000000000000000000040371301161664300353500ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/librarypackage org.malai.javafx.instrument.library; import javafx.scene.Node; import org.malai.action.Action; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxInteractor; import org.malai.javafx.interaction.library.MenuItemPressed; import java.util.List; public abstract class MenuItemInteractor
extends JfxInteractor { /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public MenuItemInteractor(I ins, Class clazzAction, List widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, MenuItemPressed.class, widgets); } /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public MenuItemInteractor(I ins, Class clazzAction, Node... widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, MenuItemPressed.class, widgets); } } SpinnerInteractor.java000066400000000000000000000053621301161664300352450ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/library/* * This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/ package org.malai.javafx.instrument.library; import java.util.List; import javafx.scene.Node; import org.malai.action.Action; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxInteractor; import org.malai.javafx.interaction.library.SpinnerValueChanged; /** * An interactor using a JFX combo box interaction. * @param
The action to produce. * @param The instrument. */ public abstract class SpinnerInteractor extends JfxInteractor { /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public SpinnerInteractor(final I ins, final Class clazzAction, final List widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, SpinnerValueChanged.class, widgets); } /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public SpinnerInteractor(final I ins, final Class clazzAction, final Node... widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, SpinnerValueChanged.class, widgets); } } ToggleButtonInteractor.java000066400000000000000000000053411301161664300362410ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/instrument/library/* * This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*/ package org.malai.javafx.instrument.library; import java.util.List; import javafx.scene.Node; import org.malai.action.Action; import org.malai.javafx.instrument.JfxInstrument; import org.malai.javafx.instrument.JfxInteractor; import org.malai.javafx.interaction.library.ToggleButtonPressed; /** * An interactor using a JFX toggle button interaction. * @param
The action to produce. * @param The instrument. */ public abstract class ToggleButtonInteractor extends JfxInteractor { /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public ToggleButtonInteractor(I ins, Class clazzAction, List widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, ToggleButtonPressed.class, widgets); } /** * Creates an interactor. * @param ins The instrument that contains the interactor. * @param clazzAction The type of the action that will be created. Used to instantiate the action by reflexivity. * The class must be public and must have a constructor with no parameter. * @param widgets The widgets used by the interactor. Cannot be null. * @throws IllegalAccessException If no free-parameter constructor is available. * @throws InstantiationException If an error occurs during instantiation of the interaction/action. * @throws IllegalArgumentException If the given interaction or instrument is null. */ public ToggleButtonInteractor(I ins, Class clazzAction, Node... widgets) throws InstantiationException, IllegalAccessException { super(ins, false, clazzAction, ToggleButtonPressed.class, widgets); } } malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/interaction/000077500000000000000000000000001301161664300274455ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/interaction/DragTransition.java000066400000000000000000000024521301161664300332430ustar00rootroot00000000000000package org.malai.javafx.interaction; import javafx.scene.input.MouseEvent; import org.malai.stateMachine.SourceableState; import org.malai.stateMachine.TargetableState; /** * This transition corresponds to a drag (move after a pressure) using a pointing device.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2014-10-11
* @author Arnaud BLOUIN */ public class DragTransition extends PointingDeviceTransition { /** * Defines a transition. * @param inputState The source state of the transition. * @param outputState The target state of the transition. * @throws IllegalArgumentException If one of the given parameters is null or not valid. */ public DragTransition(final SourceableState inputState, final TargetableState outputState) { super(inputState, outputState); } } EscapeKeyPressureTransition.java000066400000000000000000000024221301161664300357060ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/interactionpackage org.malai.javafx.interaction; import javafx.scene.input.KeyCode; import org.malai.stateMachine.SourceableState; import org.malai.stateMachine.TargetableState; /** * This transition should be used to cancel an interaction using key ESCAPE. *
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* 2014-09-23
* @author Arnaud BLOUIN */ public class EscapeKeyPressureTransition extends KeyPressureTransition { /** * Creates the transition. * @param inputState The source state. * @param outputState The target state. * @since 0.2 */ public EscapeKeyPressureTransition(final SourceableState inputState, final TargetableState outputState) { super(inputState, outputState); } @Override public boolean isGuardRespected() { return event.getCode()==KeyCode.ESCAPE; } } JfxBoxCheckedTransition.java000066400000000000000000000022751301161664300347610ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/interactionpackage org.malai.javafx.interaction; import javafx.scene.control.CheckBox; import org.malai.interaction.TransitionImpl; import org.malai.interaction.WidgetTransition; import org.malai.stateMachine.SourceableState; import org.malai.stateMachine.TargetableState; /** * A transition based on the onAction event of check boxes.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* @author Arnaud BLOUIN */ public class JfxBoxCheckedTransition extends WidgetTransition { /** * {@link TransitionImpl#Transition(SourceableState, TargetableState)} */ public JfxBoxCheckedTransition(final SourceableState inputState, final TargetableState outputState) { super(inputState, outputState); } } JfxButtonPressedTransition.java000066400000000000000000000022731301161664300355610ustar00rootroot00000000000000malai-2.0+ds1/malai-core/org.malai.javafx/src/main/org/malai/javafx/interactionpackage org.malai.javafx.interaction; import javafx.scene.control.Button; import org.malai.interaction.TransitionImpl; import org.malai.interaction.WidgetTransition; import org.malai.stateMachine.SourceableState; import org.malai.stateMachine.TargetableState; /** * A transition based on the onAction event of buttons.
*
* This file is part of Malai.
* Copyright (c) 2005-2015 Arnaud BLOUIN
*
* Malai is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later version. *
* Malai is distributed without any warranty; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* @author Arnaud BLOUIN */ public class JfxButtonPressedTransition extends WidgetTransition