/** * Creates a new {@link ChannelImpl} instance based on a given channel. * * @param aChannel * the channel to copy, cannot be <code>null</code>; * @param aRetainAnnotation * <code>true</code> if any annotations should be retained, * <code>false</code> otherwise. */ public ChannelImpl( final Channel aChannel, final boolean aRetainAnnotation ) { if ( aChannel == null ) { throw new IllegalArgumentException( "Channel cannot be null!" ); } this.propertyChangeSupport = new PropertyChangeSupport( this ); this.index = aChannel.getIndex(); this.mask = aChannel.getMask(); this.label = aChannel.hasName() ? aChannel.getLabel() : null; this.enabled = aChannel.isEnabled(); this.annotations = new CopyOnWriteArrayList<Annotation<?>>(); if ( aRetainAnnotation ) { this.annotations.addAll( aChannel.getAnnotations() ); } }
/** * Trims the channels to the same number as the captured data, using the * channel information of the given data set as template. * * @param aLabels * the channel labels to merge, can be <code>null</code>. */ final void mergeChannelLabels( final List<String> aLabels ) { if ( aLabels == null ) { return; } int channelCount = Math.min( aLabels.size(), this.channels.length ); for ( int i = 0; i < channelCount; i++ ) { Channel channel = this.channels[i]; // Channels might be null, especially when importing projects from older // versions of the client... if ( channel != null ) { channel.setLabel( aLabels.get( i ) ); } } }
@Override public Component getListCellRendererComponent( final JList aList, final Object aValue, final int aIndex, final boolean aIsSelected, final boolean aCellHasFocus ) { StringBuilder sb = new StringBuilder(); if ( ( aValue != null ) && ( aValue instanceof Channel ) ) { final Channel channel = ( Channel )aValue; sb.append( channel.getIndex() ); if ( channel.hasName() ) { sb.append( ", " ).append( channel.getLabel() ); } } return super.getListCellRendererComponent( aList, sb.toString(), aIndex, aIsSelected, aCellHasFocus ); } }
/** * {@inheritDoc} */ @Override public int compareTo( final Channel aChannel ) { return ( this.index - aChannel.getIndex() ); }
/** * @param aChannelCount * @return */ private void createChannelHeaders( final List<String> aList, final Channel[] aChannels ) { final int insertIdx = aList.size(); for ( int i = 0; i < aChannels.length; i++ ) { String label = aChannels[i].getLabel(); if ( label == null ) { label = String.format( "Ch.%d", Integer.valueOf( i ) ); } // Causes the channels to be listed in "inverse" order, MSB first... aList.add( insertIdx, label ); } }
/** * Determines whether or not there are annotations available for the signal * element. * * @return <code>true</code> if there are any annotations available for the * channel, <code>false</code> otherwise. */ private boolean hasAnnotations() { return !getChannel().getAnnotations().isEmpty(); } }
/** * Returns whether a channel label is set or not. * * @param aChannelIdx * the channel index to check whether its label is set, >= 0 && < 32. * @return <code>true</code> if there a non-empty label set for the given * channel index, <code>false</code> otherwise. */ public boolean isChannelLabelSet( final int aChannelIdx ) { if ( ( aChannelIdx < 0 ) || ( aChannelIdx > ( Ols.MAX_CHANNELS - 1 ) ) ) { throw new IllegalArgumentException( "Invalid channel index: " + aChannelIdx + "! Should be between 0 and " + Ols.MAX_CHANNELS ); } final Channel channel = getAllChannels()[aChannelIdx]; return channel.hasName(); }
/** * Factory method for creating a {@link SignalElement} instance representing a * digital signal. * * @param aChannel * the channel to create a channel element for, cannot be * <code>null</code>. * @return a new {@link SignalElement} instance, never <code>null</code>. */ public static SignalElement createDigitalSignalElement( final Channel aChannel, final ElementGroup aGroup ) { int index = aGroup.getElementCount(); SignalElement channelElement = new SignalElement( SignalElementType.DIGITAL_SIGNAL, index, aChannel.getMask() ); channelElement.channel = aChannel; channelElement.group = aGroup; channelElement.height = UIManager.getInt( CHANNEL_HEIGHT ); channelElement.signalHeight = UIManager.getInt( DIGITAL_SIGNAL_HEIGHT ); channelElement.alignment = SignalAlignment.valueOf( getUIManagerValue( SIGNALVIEW_SIGNAL_ALIGNMENT, "CENTER" ) ); return channelElement; }
if ( ( channel == null ) || !channel.isEnabled() )
/** * {@inheritDoc} */ @Override public int compareTo( final Channel aChannel ) { return this.index - aChannel.getIndex(); }
/** * Returns the channel label. * * @param aChannelIdx * the index of the channel to retrieve the label for, >= 0 && < * {@value nl.lxtreme.ols.api.Ols#MAX_CHANNELS}. * @return the channel's label, can be <code>null</code>. */ public String getChannelLabel( final int aChannelIdx ) { if ( ( aChannelIdx < 0 ) || ( aChannelIdx > ( Ols.MAX_CHANNELS - 1 ) ) ) { throw new IllegalArgumentException( "Invalid channel index: " + aChannelIdx + "! Should be between 0 and " + Ols.MAX_CHANNELS ); } return getAllChannels()[aChannelIdx].getLabel(); }
for ( Annotation<?> annotation : this.channel.getAnnotations() )
/** * Returns whether or not this signal element is enabled. * * @return */ public boolean isEnabled() { if ( this.channel != null ) { return this.channel.isEnabled(); } else if ( this.group != null ) { if ( isGroupSummary() ) { return this.group.isShowGroupSummary(); } else if ( isAnalogSignal() ) { return this.group.isShowAnalogSignal(); } else { throw new InternalError( "Unknown signal element?! Type = " + this.type ); } } return false; }
/** * @return */ private String getColorKey() { Integer groupIdx = Integer.valueOf( ( this.group.getIndex() % 4 ) + 1 ); // Issue #121: channel can be null for non-digital channels... if ( this.channel != null ) { Integer channelIdx = Integer.valueOf( ( this.channel.getIndex() % 8 ) + 1 ); return String.format( "ols.channelgroup%d.channel%d.default.color", groupIdx, channelIdx ); } return String.format( "ols.channelgroup%d.default.color", groupIdx ); }
/** * Writes down all variable definitions. * * @param aWriter * the print writer to write to, cannot be <code>null</code>; * @param aContainer * the data container to take the channel information from, cannot be * <code>null</code>. */ protected void writeVariableDefinitions( final PrintWriter aWriter, final DataSet aDataSet ) { final AcquisitionResult capturedData = aDataSet.getCapturedData(); final int channelMask = capturedData.getEnabledChannels(); final Channel[] channelLabels = aDataSet.getChannels(); for ( int i = 0; i < channelLabels.length; i++ ) { if ( ( channelMask & ( 1 << i ) ) == 0 ) { continue; } String label = channelLabels[i].getLabel(); if ( StringUtils.isEmpty( label ) ) { label = "channel" + i; } writeVariable( aWriter, i, label ); } }
/** * Sets the channel label. * * @param aChannelIdx * the index of the channel to set the label for, >= 0 && < 32; * @param aLabel * the label to set, may be <code>null</code>. */ public void setChannelLabel( final int aChannelIdx, final String aLabel ) { if ( ( aChannelIdx < 0 ) || ( aChannelIdx > ( Ols.MAX_CHANNELS - 1 ) ) ) { throw new IllegalArgumentException( "Invalid channel index: " + aChannelIdx + "! Should be between 0 and " + Ols.MAX_CHANNELS ); } getAllChannels()[aChannelIdx].setLabel( aLabel ); }
/** * Finds the first annotation that starts and ends after the given timestamp. * * @param aTimestamp * the timestamp to search for annotations, >= 0L. * @return an annotation matching the given timestamp criteria, * <code>null</code> if not found. */ public DataAnnotation<?> getAnnotationAfter( final long aTimestamp ) { SortedSet<Annotation<?>> annotations = new TreeSet<Annotation<?>>( this.channel.getAnnotations() ); for ( Annotation<?> annotation : annotations ) { if ( !( annotation instanceof DataAnnotation<?> ) ) { continue; } final DataAnnotation<?> ann = ( DataAnnotation<?> )annotation; final long annStartTime = ann.getStartTimestamp(); final long annEndTime = ann.getEndTimestamp(); if ( ( annStartTime >= aTimestamp ) && ( annEndTime >= aTimestamp ) ) { return ann; } } return null; }