Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/openbase/bco.dal
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineThreepwood committed Oct 22, 2018
2 parents 8903406 + 1e76692 commit 5a7ceb9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 18 deletions.
Expand Up @@ -24,8 +24,10 @@
*
* @author <a href="mailto:divine@openbase.org">Divine Threepwood</a>
*/
import org.openbase.bco.dal.lib.jp.JPUnitAllocation;
import org.openbase.bco.dal.lib.layer.unit.agent.AgentManager;
import org.openbase.bco.registry.lib.BCO;
import org.openbase.jps.core.JPService;
import org.openbase.jul.pattern.launch.AbstractLauncher;
import org.openbase.jul.exception.CouldNotPerformException;
import org.openbase.jul.exception.InstantiationException;
Expand All @@ -38,7 +40,7 @@ public AgentManagerLauncher() throws InstantiationException {

@Override
protected void loadProperties() {

JPService.registerProperty(JPUnitAllocation.class);
}

/**
Expand Down
Expand Up @@ -48,8 +48,6 @@ public void loadProperties() {
JPService.registerProperty(JPPrefix.class);
JPService.registerProperty(JPHardwareSimulationMode.class);
JPService.registerProperty(JPBenchmarkMode.class);
JPService.registerProperty(JPUnitRegistryScope.class);
JPService.registerProperty(JPClassRegistryScope.class);
JPService.registerProperty(JPUnitAllocation.class);
JPService.registerProperty(JPProviderControlMode.class);
}
Expand Down
Expand Up @@ -16,17 +16,23 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="presenceStatePanel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Component id="applyPresenceStateButton" alignment="1" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="presenceStatePanel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lastPresenceValueLabel" max="32767" attributes="0"/>
<Component id="lastPresenceValueLabel" pref="319" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
Expand All @@ -37,7 +43,9 @@
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="presenceStatePanel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="32" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="58" max="-2" attributes="0"/>
<Component id="applyPresenceStateButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
Expand All @@ -46,7 +54,7 @@
<Component id="lastPresenceValueLabel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace pref="74" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
Expand All @@ -65,12 +73,15 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="stateLabel" alignment="1" pref="249" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="stateLabel" min="-2" pref="484" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="stateLabel" alignment="1" pref="40" max="32767" attributes="0"/>
<Component id="stateLabel" alignment="1" pref="36" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
Expand All @@ -96,5 +107,13 @@
<Property name="text" type="java.lang.String" value="Last Presence:"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="applyPresenceStateButton">
<Properties>
<Property name="text" type="java.lang.String" value="PresenseState"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="applyPresenceStateButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
Expand Up @@ -24,18 +24,24 @@
import java.awt.Color;
import java.text.DateFormat;
import java.util.Date;
import org.openbase.bco.dal.lib.action.ActionDescriptionProcessor;
import org.openbase.bco.dal.lib.jp.JPProviderControlMode;

import org.openbase.bco.dal.lib.layer.service.Services;
import org.openbase.bco.dal.lib.layer.service.consumer.ConsumerService;
import org.openbase.bco.dal.lib.layer.service.operation.OperationService;
import org.openbase.bco.dal.lib.layer.service.provider.PresenceStateProviderService;
import org.openbase.jps.core.JPService;
import org.openbase.jps.exception.JPNotAvailableException;
import org.openbase.jul.exception.CouldNotPerformException;
import org.openbase.jul.exception.InvalidStateException;
import org.openbase.jul.exception.NotAvailableException;
import org.openbase.jul.exception.printer.ExceptionPrinter;
import org.openbase.jul.exception.printer.LogLevel;
import org.openbase.jul.extension.rst.processing.TimestampJavaTimeTransform;
import org.openbase.jul.processing.StringProcessor;
import rst.domotic.action.ActionDescriptionType.ActionDescription;
import rst.domotic.service.ServiceTemplateType;
import rst.domotic.state.PresenceStateType.PresenceState;
import rst.domotic.state.PresenceStateType.PresenceState.State;

Expand All @@ -54,6 +60,13 @@ public class PresenceStateServicePanel extends AbstractServicePanel<PresenceStat
*/
public PresenceStateServicePanel() throws org.openbase.jul.exception.InstantiationException {
initComponents();

try {
applyPresenceStateButton.setVisible(JPService.getProperty(JPProviderControlMode.class).getValue());
} catch (JPNotAvailableException ex) {
applyPresenceStateButton.setVisible(false);
ExceptionPrinter.printHistory(ex, logger, LogLevel.ERROR);
}
}

/** This method is called from within the constructor to
Expand All @@ -69,6 +82,7 @@ private void initComponents() {
stateLabel = new javax.swing.JLabel();
lastPresenceValueLabel = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
applyPresenceStateButton = new javax.swing.JButton();

presenceStatePanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));

Expand All @@ -80,50 +94,84 @@ private void initComponents() {
presenceStatePanel.setLayout(presenceStatePanelLayout);
presenceStatePanelLayout.setHorizontalGroup(
presenceStatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(stateLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
.addGroup(presenceStatePanelLayout.createSequentialGroup()
.addComponent(stateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 484, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
presenceStatePanelLayout.setVerticalGroup(
presenceStatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(stateLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
.addComponent(stateLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
);

lastPresenceValueLabel.setText("N/A");

jLabel2.setText("Last Presence:");

applyPresenceStateButton.setText("PresenseState");
applyPresenceStateButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
applyPresenceStateButtonActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(presenceStatePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(presenceStatePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(applyPresenceStateButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lastPresenceValueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lastPresenceValueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
.addContainerGap()))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(presenceStatePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(32, Short.MAX_VALUE))
.addGap(58, 58, 58)
.addComponent(applyPresenceStateButton)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(64, 64, 64)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lastPresenceValueLabel)
.addComponent(jLabel2))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap(74, Short.MAX_VALUE)))
);
}// </editor-fold>//GEN-END:initComponents

private void applyPresenceStateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyPresenceStateButtonActionPerformed
try {
PresenceState presenceState;
switch (getProviderService().getPresenceState().getValue()) {
case PRESENT:
presenceState = PresenceState.newBuilder().setValue(PresenceState.State.ABSENT).build();
break;
default:
presenceState = PresenceState.newBuilder().setValue(PresenceState.State.PRESENT).build();
break;
}
ActionDescription action = ActionDescriptionProcessor.generateActionDescriptionBuilder(presenceState, ServiceTemplateType.ServiceTemplate.ServiceType.PRESENCE_STATE_SERVICE, getUnitRemote()).build();
notifyActionProcessing(getUnitRemote().applyAction(action));
} catch (CouldNotPerformException ex) {
ExceptionPrinter.printHistory(ex, logger, LogLevel.ERROR);
}
}//GEN-LAST:event_applyPresenceStateButtonActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton applyPresenceStateButton;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel lastPresenceValueLabel;
private javax.swing.JPanel presenceStatePanel;
Expand Down

0 comments on commit 5a7ceb9

Please sign in to comment.