Skip to content

Commit

Permalink
Added connection toolbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed May 24, 2015
1 parent 5a887d1 commit 5fa771a
Show file tree
Hide file tree
Showing 26 changed files with 854 additions and 254 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -23,4 +23,5 @@ tar.gz
/UGSPlatform/MachineControl/build/
/UGSPlatform/MachineControl/nbproject/private/
/UGSPlatform/CentralLookup/nbproject/private/
/UGSPlatform/Options/nbproject/private/
/UGSPlatform/Options/nbproject/private/
/UGSPlatform/VisualizerModule/build/
4 changes: 2 additions & 2 deletions UGSPlatform/ConnectionModule/nbproject/genfiles.properties
@@ -1,8 +1,8 @@
build.xml.data.CRC32=a0573083
build.xml.data.CRC32=2724fb68
build.xml.script.CRC32=30d3d74e
build.xml.stylesheet.CRC32=a56c6a5b@2.67.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=a0573083
nbproject/build-impl.xml.data.CRC32=2724fb68
nbproject/build-impl.xml.script.CRC32=5eca1724
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.67.1
8 changes: 8 additions & 0 deletions UGSPlatform/ConnectionModule/nbproject/project.xml
Expand Up @@ -55,6 +55,14 @@
<specification-version>7.38.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.modules</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.43.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
Expand Down
@@ -1,4 +1,6 @@
OpenIDE-Module-Name=Connection Module
SerialPortToolbarBox.Port.text=Port:
SerialPortToolbarBox.Baud.text=Baud:
ConnectionGUITopComponent.connectionPanel.border.title=Connection
ConnectionGUITopComponent.firmwareLabel.text=Firmware:
ConnectionGUITopComponent.portLabel.text=Port:
Expand Down
@@ -0,0 +1,107 @@
/*
Copywrite 2015 Will Winder
This file is part of Universal Gcode Sender (UGS).
UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UGS 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.ugs.nbp.connection;

import com.willwinder.ugs.nbp.lookup.CentralLookup;
import com.willwinder.universalgcodesender.listeners.ControlStateListener;
import com.willwinder.universalgcodesender.model.BackendAPI;
import com.willwinder.universalgcodesender.model.ControlStateEvent.event;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractAction;
import javax.swing.Action;
import static javax.swing.Action.SMALL_ICON;
import javax.swing.Icon;
import javax.swing.JComboBox;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionRegistration;
import org.openide.util.ContextAwareAction;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;

@ActionID(
category = "Edit",
id = "com.willwinder.ugs.nbp.connectiontoolbar.ConnectDisconnect"
)
@ActionRegistration(
displayName = "#CTL_Connect",
lazy = false
)
@ActionReference(path = "Toolbars/Connection", position = 1)
@NbBundle.Messages("CTL_Connect=Connect")

//@NbBundle.Messages("CTL_Disconnect=Disconnect")

public final class ConnectDisconnectAction extends AbstractAction implements ContextAwareAction, ControlStateListener {
BackendAPI backend;
private String CONNECT_ICON_PATH = "resources/disconnect.gif";
private String DISCONNECT_ICON_PATH = "resources/connect.png";

public ConnectDisconnectAction() {
this (Utilities.actionsGlobalContext());
}

public ConnectDisconnectAction(Lookup lookup) {
Icon icon = ImageUtilities.image2Icon(ImageUtilities.loadImage(CONNECT_ICON_PATH));
putValue(SMALL_ICON, icon);

this.setEnabled(true);

backend = CentralLookup.getDefault().lookup(BackendAPI.class);
backend.addControlStateListener(this);
}

@Override
public Action createContextAwareInstance(Lookup actionContext) {
return new ConnectDisconnectAction(actionContext);
}

@Override
public void ControlStateEvent(com.willwinder.universalgcodesender.model.ControlStateEvent cse) {
if (cse.getEventType() == event.STATE_CHANGED) {
Icon icon = null;
switch (cse.getState()) {
case COMM_IDLE:
icon = ImageUtilities.image2Icon(ImageUtilities.loadImage(DISCONNECT_ICON_PATH));
break;
case COMM_DISCONNECTED:
icon = ImageUtilities.image2Icon(ImageUtilities.loadImage(CONNECT_ICON_PATH));
break;
}

if (icon != null) {
putValue(SMALL_ICON, icon);
}
}
}

@Override
public void actionPerformed(ActionEvent e) {
try {
ConnectionGUITopComponent.connect();
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
}
Expand Up @@ -111,6 +111,12 @@
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="commPortComboBoxActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JComboBox" name="baudrateSelectionComboBox">
<Properties>
Expand All @@ -133,6 +139,9 @@
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="baudrateSelectionComboBoxActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="opencloseButton">
<Properties>
Expand Down Expand Up @@ -182,6 +191,12 @@
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="firmwareComboBoxActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
Expand Down

0 comments on commit 5fa771a

Please sign in to comment.