Commit d49becf6 authored by Christophe Demarey's avatar Christophe Demarey
Browse files

Add an explorer plugin for the calculator example.

parent 7dba4f3a
/***
* OW2 FraSCAti Examples: Soap calculator
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Christophe Demarey
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.soapcalc.explorer;
import org.ow2.frascati.examples.soapcalc.api.CalcService;
import org.ow2.frascati.explorer.action.AbstractAlwaysEnabledMenuItem;
/**
* Is the FraSCAti Explorer plugin to execute {@link CalcService#add(int,int)}.
*
* @author Christophe Demarey
*/
public class CalculatorMenuItem extends AbstractAlwaysEnabledMenuItem<CalcService> {
/**
* @see org.ow2.frascati.explorer.action.AbstractAlwaysEnabledMenuItem#execute()
*/
@Override
protected void execute(CalcService calc) {
System.out.println("1 + 2 = " + calc.add(2, 1));
}
}
/***
* OW2 FraSCAti Examples: Soap Calculator
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Christophe Demarey
*
* Contributor(s):
*
*/
package org.ow2.frascati.examples.soapcalc.explorer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import org.ow2.frascati.examples.soapcalc.api.CalcService;
import org.ow2.frascati.explorer.gui.AbstractSelectionPanel;
/**
* Is the FraSCAti Explorer plugin to show {@link CalcService} instances.
*
* @author Christophe Demarey
*/
@SuppressWarnings("serial")
public class CalculatorPanel extends AbstractSelectionPanel<CalcService> {
private JButton jButtonAdd;
private JButton jButtonDiv;
private JButton jButtonMult;
private JButton jButtonSub;
private JLabel jLabel1;
private JLabel jLabel3;
private JLabel jLabel5;
private JLabel jLabel7;
private JLabel jLabelAddResult;
private JLabel jLabelDivResult;
private JLabel jLabelMultResult;
private JLabel jLabelSubResult;
private JTextField jTextField1;
private JTextField jTextField2;
private JTextField jTextField3;
private JTextField jTextField4;
private JTextField jTextField5;
private JTextField jTextField6;
private JTextField jTextField7;
private JTextField jTextField8;
/**
* Default constructor creates the panel.
*/
public CalculatorPanel() {
super();
jButtonAdd = new JButton("=");
jTextField1 = new JTextField();
jLabel1 = new JLabel("+");
jLabelAddResult = new JLabel();
jTextField2 = new JTextField();
jLabel3 = new JLabel("-");
jTextField3 = new JTextField();
jLabelSubResult = new JLabel();
jTextField4 = new JTextField();
jButtonSub = new JButton("=");
jLabel5 = new JLabel("*");
jTextField5 = new JTextField();
jLabelMultResult = new JLabel();
jTextField6 = new JTextField();
jButtonMult = new JButton("=");
jLabel7 = new JLabel("/");
jTextField7 = new JTextField();
jLabelDivResult = new JLabel();
jTextField8 = new JTextField();
jButtonDiv = new JButton("=");
// layout
GroupLayout mainPanelLayout = new GroupLayout(this);
this.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jTextField4, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jTextField8, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jTextField6, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(jTextField7, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField5, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButtonSub)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabelSubResult, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButtonDiv)
.addGap(18, 18, 18)
.addComponent(jLabelDivResult, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButtonMult)
.addGap(18, 18, 18)
.addComponent(jLabelMultResult, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButtonAdd)
.addGap(18, 18, 18)
.addComponent(jLabelAddResult, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(178, Short.MAX_VALUE))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(14, 14, 14)
.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(jButtonAdd)
.addComponent(jLabelAddResult, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jTextField4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jLabelSubResult, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
.addComponent(jButtonSub)
.addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jTextField6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(jButtonMult)
.addComponent(jLabelMultResult, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jTextField8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)
.addComponent(jButtonDiv)
.addComponent(jLabelDivResult, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addContainerGap(259, Short.MAX_VALUE))
);
// actions
jButtonAdd.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
int result = selected.add( Integer.parseInt(jTextField1.getText()),
Integer.parseInt(jTextField2.getText()) );
jLabelAddResult.setText(Integer.toString(result));
}
}
);
jButtonSub.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
int result = selected.sub( Integer.parseInt(jTextField4.getText()),
Integer.parseInt(jTextField3.getText()) );
jLabelSubResult.setText(Integer.toString(result));
}
}
);
jButtonMult.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
int result = selected.mult( Integer.parseInt(jTextField5.getText()),
Integer.parseInt(jTextField6.getText()) );
jLabelMultResult.setText(Integer.toString(result));
}
}
);
jButtonDiv.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
double result = selected.div( Integer.parseInt(jTextField7.getText()),
Integer.parseInt(jTextField8.getText()) );
jLabelDivResult.setText(Double.toString(result));
}
}
);
}
}
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
* ====================================================================
*
* OW2 FraSCAti Examples: Soap calculator
* Copyright (C) 2009 INRIA, USTL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Contact: frascati@ow2.org
*
* Author: Christophe Demarey
*
* Contributor(s):
* ====================================================================
-->
<explorer>
<!-- ================================================================= -->
<!-- FraSCAti Explorer plugins for this example. -->
<!-- ================================================================= -->
<node type-name="org.ow2.frascati.examples.soapcalc.api.CalcService">
<menu>
<item label="Add 1 to 2 ...">
<code>org.ow2.frascati.examples.soapcalc.explorer.CalculatorMenuItem</code>
</item>
</menu>
<panel>
<code>org.ow2.frascati.examples.soapcalc.explorer.CalculatorPanel</code>
</panel>
</node>
</explorer>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment