argumentGroup
element specifies a group of command-line arguments which is handled by the listener.key
attribute (mandatory) is the argument namepreventOpening
attribute (optional) specified that if this argument group is present, the application must not be made visibleargument
children which specify the arguments which are parts of the group. Each child element have the following attributes:key
attribute (mandatory) is the argument name. This argument msut be present as a top-level argument
in the xml filemandatory
attribute is a boolean specifying if the argument is mandatory (by default the argument is optional)preventOpening
attribute (optional) specified that if the argument group is present, the application must not be made visible.<argument key="analyze" type="empty" /> <argument key="image" type="url" /> <argumentGroup key="analyze" preventOpening="true"> <argument key="analyze" mandatory="true" /> <argument key="image" mandatory="true" /> </argumentGroup>If at least one argument group with
preventOpening
set to true
is presrnt, for the application or a Plugin, then the CommandLineListener.preventOpeningApplication will return true
.true
.import org.mdi.app.AbstractApplication; public class MyMDI extends AbstractMDIApplication { public MyMDI() { super("MyMDI"); super.preparePanels(); // set the command-line arguments this.setCommandLineArguments(args); // apply the arguments for the application (it will indirectly call the handleCommandLineArguments method) super.applyCommandLineArguments(); } @Override public URL getCommandLineConfiguration() { return this.getClass().getResource("commandline.xml"); } public static void main(String[] args) { MyMDI mdi = new MyMDI(); mdi.setVisible(!mdi.preventOpeningApplication()); } }
<arguments> <argument key="open" type="empty" /> <argument key="image" type="url" /> <argumentGroup key="open"> <argument key="open" mandatory="true" /> <argument key="image" mandatory="true"/> </argumentGroup> </arguments>The code for the application is:
import org.mdi.app.AbstractApplication; public class MyMDI extends AbstractMDIApplication { public MyMDI() { super("MyMDI"); super.preparePanels(); // set the command-line arguments this.setCommandLineArguments(args); // apply the arguments for the application (it will indirectly call the handleCommandLineArguments method) super.applyCommandLineArguments(); } @Override public URL getCommandLineConfiguration() { return this.getClass().getResource("commandline.xml"); } @Override public void handleCommandLineArguments(Map<String, ArgumentGroup> argumentGroups, Map<String, Argument> arguments) { if (argumentGroups.containsKey("open")) { ArgumentGroup group = argumentGroups.get("open"); File file = (File) group.getArgument("image").getValue(); try { importImage(file); } catch (Exception ex) { ex.printStackTrace(); } } } public static void main(String[] args) { MyMDI mdi = new MyMDI(); mdi.setVisible(true); } }We can for example start the application with:
java -jar MyMDI.jar -open -image=myImage.png
empty
and two url
arguments:<arguments> <argument key="import" type="empty" /> <argument key="file" type="url" /> <argument key="file2" type="url" /> <argumentGroup key="import"> <argument key="import" mandatory="true" /> <argument key="file" mandatory="true"/> </argumentGroup> <argumentGroup key="compare"> <argument key="compare" mandatory="true"/> <argument key="file" mandatory="true"/> <argument key="file2" mandatory="true"/> </argumentGroup> </arguments>We can for example start the application with:
java -jar MyMDI.jar -import -file=L:/my/file.xml
In that case, there will be only one argumentGroup
for the key import
with two arguments:import
which is an empty
argumentfile
which is an url
argument
java -jar MyMDI.jar -import -file=L:/my/file.xml -compare
In that case, we will still have only one argumentGroup
for the key import
with the same two arguments, because there is a compare
argument but the file2
is absent.
empty
and one url
arguments:<argument key="open" type="empty" /> <argument key="analyze" type="empty" /> <argument key="image" type="url" /> <argumentGroup key="open"> <argument key="open" mandatory="true" /> <argument key="image" mandatory="true" /> </argumentGroup> <argumentGroup key="analyze" preventOpening="true"> <argument key="analyze" mandatory="true" /> <argument key="image" mandatory="true" /> </argumentGroup>If the
analyze
group is present, the application must not be set visible.
java -jar MyMDI.jar -open -image=image.png
In that case, there will be only one argumentGroup
for the key open
with two arguments:open
which is an empty
argumentimage
which is an url
argument
java -jar MyMDI.jar -analyze -image=image.png
In that case, there will be only one argumentGroup
for the key open
with two arguments:analyze
which is an empty
argumentimage
which is an url
argumentCopyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences