|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
Access "Define Parameters" window per Button event? |
ayk
|
Post subject: Access "Define Parameters" window per Button event? |
Post rating: 0
|
Posted: Mon 15 Aug, 2011, 07:54
|
|
User rating: 0
Joined: Thu 28 Jul, 2011, 11:38 Posts: 9 Location: GermanyGermany
|
Is it possible to open define parameters window per own button in a jframe or panel?
Greetings ayk
|
|
|
|
 |
API Support
|
Post subject: Re: Access "Define Parameters" window per Button event? |
Post rating: 0
|
Posted: Mon 15 Aug, 2011, 10:38
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Currently it is not possible to access Define Parameters dialog from API. However you can create your own GUI element which allows to modify the configurable parameters, for GUI extending example see: https://www.dukascopy.com/wiki/index.php ... _InterfaceIf you wish to edit the parameters during the strategy run, simply right-click on it in Workspace panel and select Parameters. If you wish to do it from standalone API, retrieve your running strategy from IClient.getStartedStrategies() and then assign a new parameter value, e.g.: for (IStrategy s : client.getStartedStrategies().values()) { MyStrategy strategy = (MyStrategy) s; if (strategy != null) strategy.intParam = 7; }
|
|
|
|
 |
SFXbernhard
|
Post subject: Re: Access "Define Parameters" window per Button event? |
Post rating: 0
|
Posted: Tue 26 Jun, 2012, 10:04
|
|
User rating: 21
Joined: Thu 19 May, 2011, 20:50 Posts: 413 Location: Germany, Munich
|
API Support wrote: Currently it is not possible to access Define Parameters dialog from API. Dear Support, even if it is not possible to access the Define Parameters dialog from the API, it would be nice to create an own parameter window though. Could you open this container for access in the API? Or did you use an Open Source one so I can implement this into my projects?
|
|
|
|
 |
API Support
|
Post subject: Re: Access "Define Parameters" window per Button event? |
Post rating: 0
|
Posted: Tue 26 Jun, 2012, 10:12
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
SFXbernhard wrote: even if it is not possible to access the Define Parameters dialog from the API, it would be nice to create an own parameter window though. All java swing is at your disposal, so if you wish to create a custom parameters dialog, you can do it in the onStart method of your strategy. SFXbernhard wrote: Could you open this container for access in the API? What additional functionality do you require?
|
|
|
|
 |
SFXbernhard
|
Post subject: Re: Access "Define Parameters" window per Button event? |
Post rating: 0
|
Posted: Tue 26 Jun, 2012, 16:26
|
|
User rating: 21
Joined: Thu 19 May, 2011, 20:50 Posts: 413 Location: Germany, Munich
|
I just want to use the Define Parameters dialog as JForex uses it, from your side I do not need any further platform implementation (such as strategy start/stop). How can I access this Component or instantiate it then?
|
|
|
|
 |
API Support
|
Post subject: Re: Access "Define Parameters" window per Button event? |
Post rating: 0
|
Posted: Tue 26 Jun, 2012, 18:03
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
SFXbernhard wrote: How can I access this Component or instantiate it then? You can not access it because it is not part of JForex-API. If you wish to have a customized parameters' dialog, consider doing something like this: package jforex.guitests;
import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map;
import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities;
import com.dukascopy.api.IAccount; import com.dukascopy.api.IBar; import com.dukascopy.api.IConsole; import com.dukascopy.api.IContext; import com.dukascopy.api.IMessage; import com.dukascopy.api.IStrategy; import com.dukascopy.api.ITick; import com.dukascopy.api.Instrument; import com.dukascopy.api.JFException; import com.dukascopy.api.Period;
@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface Param { String value(); }
/** * The strategy demonstrates how one can create his own parameter dialog. * Launch the strategy, change the parameters and check the console that they have been successfully changed. * Note to input proper values according to parameter type * */ public class MyParamStrategy implements IStrategy {
@Param("boolean param description") public boolean booleanParam = true; @Param("double param description") public double doubleParam = 5.0; @Param("int param description") public int intParam = 5; @Param("string param description") public String stringParam = "some string";
private IConsole console;
public void onStart(IContext context) throws JFException {
this.console = context.getConsole(); printFields("Parameters before:"); try { SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() { new ParamDialog(MyParamStrategy.this); } }); } catch (InterruptedException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); }
printFields("Parameters after:"); } private void printFields(String comment){ console.getOut().println(comment); Field[] fields = this.getClass().getFields(); for (Field field : fields) { Param parameter = field.getAnnotation(Param.class); if (parameter != null) { try { console.getOut().println(String.format("Parameter %s=%s",parameter.value(), field.get(this))); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } } }
public void onTick(Instrument instrument, ITick tick) throws JFException { }
public void onStop() throws JFException {}
public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { } }
@SuppressWarnings("serial") class ParamDialog extends JDialog {
private final IStrategy strategy; private final Map<Field,JTextField> fieldMap = new HashMap<Field,JTextField>();
public ParamDialog(IStrategy strategy) { this.strategy = strategy; this.setModal(true); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int width = 150; int height = 150; int x = (screen.width - width) / 2; int y = (screen.height - height) / 2; setBounds(x, y, width, height);
addComponentsToPane(this.getContentPane()); pack(); setVisible(true); }
public void addComponentsToPane(Container pane) { pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
Field[] fields = strategy.getClass().getFields(); for (Field field : fields) { Param parameter = field.getAnnotation(Param.class); if (parameter != null) { JPanel paramPanel = new JPanel(); paramPanel.setLayout(new BoxLayout(paramPanel, BoxLayout.X_AXIS)); paramPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JLabel label = new JLabel(parameter.value()); label.setPreferredSize(new Dimension(200, 20)); paramPanel.add(label, BorderLayout.WEST); try { JTextField textField = new JTextField(String.valueOf(field.get(strategy))); textField.setHorizontalAlignment(JTextField.RIGHT); textField.setPreferredSize(new Dimension(100, 20)); paramPanel.add(textField, BorderLayout.EAST); fieldMap.put(field, textField); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } pane.add(paramPanel); } } JButton button = new JButton("OK"); button.setAlignmentX(Component.CENTER_ALIGNMENT); button.addActionListener(new ActionListener(){
@Override public void actionPerformed(ActionEvent e) { for(Map.Entry<Field, JTextField> entry : fieldMap.entrySet()){ try { Field field = entry.getKey(); String stringValue = entry.getValue().getText(); if( field.getType() == double.class){ field.set(strategy,Double.valueOf(stringValue)); } else if( field.getType() == int.class){ field.set(strategy,Integer.valueOf(stringValue)); } else if( field.getType() == boolean.class){ field.set(strategy,Boolean.valueOf(stringValue)); } else if( field.getType() == String.class){ field.set(strategy,stringValue); } } catch (IllegalArgumentException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { e1.printStackTrace(); } } ParamDialog.this.setVisible(false); ParamDialog.this.dispose(); }}); pane.add(button); }
}
Attachments: |
MyParamStrategy.java [6.96 KiB]
Downloaded 402 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
 |
SFXbernhard
|
Post subject: Re: Access "Define Parameters" window per Button event? |
Post rating: 0
|
Posted: Thu 28 Jun, 2012, 04:11
|
|
User rating: 21
Joined: Thu 19 May, 2011, 20:50 Posts: 413 Location: Germany, Munich
|
Thanks for your example. It is not the problem to write an own parameter dialog. It is just the work. The point is that your JForex parameter dialog has many specific functions that should be recoded into such an own parameter dialog. Such as date interpretation, or boolean values are displayed as checkboxes automatically, periods are displayed in comboboxes, presets can be organized and much more. It would be nice to have access to this component (and no need to copy it arduously).
|
|
|
|
 |
API Support
|
Post subject: Re: Access "Define Parameters" window per Button event? |
Post rating: 0
|
Posted: Thu 28 Jun, 2012, 07:47
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Say there would be an interface interface IParameterDialogListener{ void onDialogOpen(IParameterDialog parameterDialog); void onDialogClose(IParameterDialog parameterDialog); } , where IParameterDialog would hold some properties of the parameter dialog. Please advise what methods would you require for IParameterDialog .
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|