Adapt to API changes
This commit is contained in:
@@ -16,12 +16,17 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jPanel1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="jPanel1" max="32767" attributes="0"/>
|
||||
<Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
@@ -39,7 +44,7 @@
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace pref="188" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="58" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="buttonStart1" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart2" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
@@ -47,7 +52,7 @@
|
||||
<Component id="buttonStart4" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart5" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="189" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="59" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
@@ -112,5 +117,39 @@
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="jPanel2">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="Devices"/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="motorPanel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="motorPanel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="ch.psi.pshell.swing.MotorPanel" name="motorPanel">
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
||||
@@ -3,73 +3,44 @@
|
||||
*/
|
||||
package ch.psi.plugin;
|
||||
|
||||
import ch.psi.pshell.core.Controller;
|
||||
import ch.psi.pshell.ui.App;
|
||||
import ch.psi.pshell.ui.View;
|
||||
import ch.psi.pshell.dev.Device;
|
||||
import ch.psi.utils.State;
|
||||
import ch.psi.utils.Swing;
|
||||
import ch.psi.wsaf.ApplicationStateAdapter;
|
||||
import ch.psi.wsaf.ApplicationStateListener;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class MainPanel extends javax.swing.JPanel {
|
||||
final App app;
|
||||
final View view;
|
||||
final Controller controller;
|
||||
/**
|
||||
* Creates new form MainPanel
|
||||
*/
|
||||
public MainPanel() {
|
||||
initComponents();
|
||||
app=App.getInstance();
|
||||
controller=app.getController();
|
||||
view=(View) app.getMainFrame();
|
||||
app.addStateListener(applicationStateListener);
|
||||
}
|
||||
|
||||
ApplicationStateListener applicationStateListener = new ApplicationStateAdapter() {
|
||||
@Override
|
||||
public void onChangedState(State newState, State curState) {
|
||||
try{
|
||||
/*
|
||||
if (newState==State.Ready){
|
||||
motorPanel1.setDevice(controller.getDevicePool().getByName("motor"));
|
||||
motorPanel2.setDevice(controller.getDevicePool().getByName("m"));
|
||||
}else{
|
||||
if (!newState.isInitialized()){
|
||||
motorPanel1.setDevice(null);
|
||||
motorPanel2.setDevice(null);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
buttonStart1.setEnabled(newState==State.Ready);
|
||||
buttonStart2.setEnabled(newState==State.Ready);
|
||||
buttonStart3.setEnabled(newState==State.Ready);
|
||||
buttonStart4.setEnabled(newState==State.Ready);
|
||||
buttonStart5.setEnabled(newState==State.Ready);
|
||||
//motorPanel1.setEnabled(newState==State.Ready);
|
||||
//motorPanel2.setEnabled(newState==State.Ready);
|
||||
}
|
||||
catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
void setState(State state) {
|
||||
try{
|
||||
boolean ready = state==State.Ready;
|
||||
if (!state.isInitialized()){
|
||||
motorPanel.setDevice(null);
|
||||
}
|
||||
buttonStart1.setEnabled(ready);
|
||||
buttonStart2.setEnabled(ready);
|
||||
buttonStart3.setEnabled(ready);
|
||||
buttonStart4.setEnabled(ready);
|
||||
buttonStart5.setEnabled(ready);
|
||||
//motorPanel1.setEnabled(newState==State.Ready);
|
||||
//motorPanel2.setEnabled(newState==State.Ready);
|
||||
}
|
||||
};
|
||||
|
||||
void runScript(final String name){
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
controller.evalFile(name, true);
|
||||
}catch (Exception ex){
|
||||
Swing.showException(view, ex);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void setDevice(Device device){
|
||||
motorPanel.setDevice(device);
|
||||
}
|
||||
|
||||
protected void run(String name){
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,6 +58,8 @@ public class MainPanel extends javax.swing.JPanel {
|
||||
buttonStart3 = new javax.swing.JButton();
|
||||
buttonStart4 = new javax.swing.JButton();
|
||||
buttonStart5 = new javax.swing.JButton();
|
||||
jPanel2 = new javax.swing.JPanel();
|
||||
motorPanel = new ch.psi.pshell.swing.MotorPanel();
|
||||
|
||||
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Tasks"));
|
||||
|
||||
@@ -130,14 +103,14 @@ public class MainPanel extends javax.swing.JPanel {
|
||||
jPanel1Layout.setHorizontalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap(188, Short.MAX_VALUE)
|
||||
.addContainerGap(58, Short.MAX_VALUE)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(buttonStart1)
|
||||
.addComponent(buttonStart2)
|
||||
.addComponent(buttonStart3)
|
||||
.addComponent(buttonStart4)
|
||||
.addComponent(buttonStart5))
|
||||
.addContainerGap(189, Short.MAX_VALUE))
|
||||
.addContainerGap(59, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonStart1, buttonStart2, buttonStart3, buttonStart4, buttonStart5});
|
||||
@@ -160,41 +133,64 @@ public class MainPanel extends javax.swing.JPanel {
|
||||
|
||||
jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {buttonStart1, buttonStart2, buttonStart3, buttonStart4, buttonStart5});
|
||||
|
||||
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Devices"));
|
||||
|
||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
||||
jPanel2.setLayout(jPanel2Layout);
|
||||
jPanel2Layout.setHorizontalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(motorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
jPanel2Layout.setVerticalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(motorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void buttonStart1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart1ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
runScript("test1");
|
||||
run("test1");
|
||||
}//GEN-LAST:event_buttonStart1ActionPerformed
|
||||
|
||||
private void buttonStart2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart2ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
runScript("test2");
|
||||
run("test2");
|
||||
}//GEN-LAST:event_buttonStart2ActionPerformed
|
||||
|
||||
private void buttonStart3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart3ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
runScript("test3");
|
||||
run("test3");
|
||||
}//GEN-LAST:event_buttonStart3ActionPerformed
|
||||
|
||||
private void buttonStart4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart4ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
runScript("test4");
|
||||
run("test4");
|
||||
}//GEN-LAST:event_buttonStart4ActionPerformed
|
||||
|
||||
private void buttonStart5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart5ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
runScript("test5");
|
||||
run("test5");
|
||||
}//GEN-LAST:event_buttonStart5ActionPerformed
|
||||
|
||||
|
||||
@@ -205,5 +201,7 @@ public class MainPanel extends javax.swing.JPanel {
|
||||
private javax.swing.JButton buttonStart4;
|
||||
private javax.swing.JButton buttonStart5;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private ch.psi.pshell.swing.MotorPanel motorPanel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
package ch.psi.plugin;
|
||||
|
||||
import ch.psi.pshell.ui.Plugin;
|
||||
import ch.psi.utils.State;
|
||||
import ch.psi.utils.swing.SwingUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -13,7 +15,15 @@ public class TestPlugin extends Plugin{
|
||||
MainPanel panel;
|
||||
@Override
|
||||
protected void onStart() {
|
||||
panel = new MainPanel();
|
||||
panel = new MainPanel(){
|
||||
protected void run(String name){
|
||||
try {
|
||||
TestPlugin.this.run(name);
|
||||
} catch (Exception ex) {
|
||||
SwingUtils.showException(panel, ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
getView().getDocumentsTab().insertTab("Main",null,panel,null,0);
|
||||
getView().getDocumentsTab().setSelectedComponent(panel);
|
||||
}
|
||||
@@ -22,4 +32,16 @@ public class TestPlugin extends Plugin{
|
||||
protected void onStop() {
|
||||
|
||||
}
|
||||
|
||||
protected void onStateChange(State state, State former){
|
||||
panel.setState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInitialize(int runCount){
|
||||
panel.setDevice(getDevice("motor"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user