Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* This file is part of Kayak.
*
* Kayak 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 3 of the License, or
* (at your option) any later version.
*
* Kayak 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 Lesser General Public License
* along with Kayak. If not, see .
*
*/
package com.github.andy2003.ui.messageview;
import com.github.andy2003.core.Bus;
import com.github.andy2003.core.description.Node;
import com.github.andy2003.core.description.Label;
import com.github.andy2003.core.description.SignalDescription;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteOrder;
import java.util.Iterator;
import java.util.Set;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.util.lookup.Lookups;
/**
*
* @author Jan-Niklas Meier
*/
public class SignalDescriptionNode extends AbstractNode implements Transferable {
public static final DataFlavor SIGNAL_DATA_FLAVOR = new DataFlavor(SignalDescription.class, "SignalDescription");
public static final DataFlavor BUS_DATA_FLAVOR = new DataFlavor(Bus.class, "Bus");
private SignalDescription description;
private Bus bus;
public SignalDescription getDescription() {
return description;
}
public Bus getBus() {
return bus;
}
public SignalDescriptionNode(SignalDescription signalDescription, Bus bus) {
super(Children.LEAF, Lookups.fixed(signalDescription, bus));
this.description = signalDescription;
this.bus = bus;
setDisplayName(signalDescription.getName());
setIconBaseWithExtension("org/tango-project/tango-icon-theme/16x16/status/dialog-information.png");
}
@Override
public Transferable drag() {
return this;
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{BUS_DATA_FLAVOR, SIGNAL_DATA_FLAVOR};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor == BUS_DATA_FLAVOR || flavor == SIGNAL_DATA_FLAVOR;
}
@Override
public Object getTransferData(DataFlavor flavor) {
if (flavor == BUS_DATA_FLAVOR) {
return bus;
} else if(flavor == SIGNAL_DATA_FLAVOR) {
return description;
}
return null;
}
@Override
protected Sheet createSheet() {
Sheet s = super.createSheet();
Sheet.Set set = s.createPropertiesSet();
Property notes = new PropertySupport.ReadOnly("Notes", String.class, "Notes", "Signal description notes") {
@Override
public String getValue() throws IllegalAccessException, InvocationTargetException {
return description.getNotes();
}
};
Property unit = new PropertySupport.ReadOnly("Unit", String.class, "Unit", "Unit of the signal") {
@Override
public String getValue() throws IllegalAccessException, InvocationTargetException {
return description.getUnit();
}
};
Property byteOrder = new PropertySupport.ReadOnly("Byte order", String.class, "Byte order", "Byte order of the signal") {
@Override
public String getValue() throws IllegalAccessException, InvocationTargetException {
if(description.getByteOrder().equals(ByteOrder.BIG_ENDIAN)) {
return "Big endian";
} else {
return "Little endian";
}
}
};
Property type = new PropertySupport.ReadOnly("Type", String.class, "Type", "Type of the signal") {
@Override
public String getValue() throws IllegalAccessException, InvocationTargetException {
SignalDescription.Type type = description.getType();
switch(type) {
case DOUBLE:
return "Double";
case SIGNED:
return "Signed";
case SINGLE:
return "Single";
case UNSIGNED:
return "Unsigned";
default:
return "";
}
}
};
Property offset = new PropertySupport.ReadOnly("Offset", Integer.class, "Offset", "Offset (in bit) of the signal in the frame") {
@Override
public Integer getValue() throws IllegalAccessException, InvocationTargetException {
return description.getOffset();
}
};
Property length = new PropertySupport.ReadOnly("Length", Integer.class, "Length", "Length (in bit) of the signal in the frame") {
@Override
public Integer getValue() throws IllegalAccessException, InvocationTargetException {
return description.getLength();
}
};
Property slope = new PropertySupport.ReadOnly("Slope", Double.class, "Slope", "Slope of the signal") {
@Override
public Double getValue() throws IllegalAccessException, InvocationTargetException {
return description.getSlope();
}
};
Property multiplexed = new PropertySupport.ReadOnly("Multiplexed", Boolean.class, "Multiplexed", "Set if the signal is multiplexed") {
@Override
public Boolean getValue() throws IllegalAccessException, InvocationTargetException {
return description.isMultiplexed();
}
};
Property multiplexCount = new PropertySupport.ReadOnly("Multiplex count", Long.class, "Multiplex count", "Value the multiplex counter must have for this signal.") {
@Override
public Long getValue() throws IllegalAccessException, InvocationTargetException {
return description.getMultiplexCount();
}
};
Property intercept = new PropertySupport.ReadOnly("Intercept", Double.class, "Intercept", "Intercept of the signal") {
@Override
public Double getValue() throws IllegalAccessException, InvocationTargetException {
return description.getIntercept();
}
};
Property consumer = new PropertySupport.ReadOnly("Consumer", String.class, "Consumer", "Bus nodes that consume this signal") {
@Override
public String getValue() throws IllegalAccessException, InvocationTargetException {
Set consumers = description.getConsumers();
StringBuilder sb = new StringBuilder();
Iterator it = consumers.iterator();
while(it.hasNext()) {
sb.append(it.next().getName());
if(it.hasNext())
sb.append(", ");
}
return sb.toString();
}
};
Property labels = new PropertySupport.ReadOnly("Labels", String.class, "Labels", "Labels that are defined in the signal description") {
@Override
public String getValue() throws IllegalAccessException, InvocationTargetException {
Set