Search in sources :

Example 1 with ArchiveTag

use of org.yamcs.protobuf.Yamcs.ArchiveTag in project yamcs-studio by yamcs.

the class TagBox method showPopup.

void showPopup(final MouseEvent e) {
    if (selectedIndex != -1) {
        ArchiveTag selectedTag = tags.get(selectedRow).get(selectedIndex);
        tagLabelItem.setText(selectedTag.getName());
        editTagPopup.validate();
        editTagPopup.show(e.getComponent(), e.getX(), e.getY());
    }
}
Also used : ArchiveTag(org.yamcs.protobuf.Yamcs.ArchiveTag)

Example 2 with ArchiveTag

use of org.yamcs.protobuf.Yamcs.ArchiveTag in project yamcs-studio by yamcs.

the class TagTimeline method paintComponent.

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (image == null) {
        image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D big = image.createGraphics();
        big.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));
        big.fillRect(0, 0, getWidth(), getHeight());
        big.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        for (ArchiveTag at : tags) {
            // TODO store these values in a map, rather than calculating all the time
            RGB rgb = toRGB(at);
            Color bgcolor = new Color(rgb.red, rgb.green, rgb.blue);
            int brightness = (int) Math.sqrt(.241 * rgb.red * rgb.red + .691 * rgb.green * rgb.green + .068 * rgb.blue * rgb.blue);
            Color fgcolor = (brightness < 130) ? Color.WHITE : Color.BLACK;
            big.setColor(bgcolor);
            long start = (at.hasStart()) ? at.getStart() : zoom.startInstant;
            int x1 = zoom.convertInstantToPixel(start);
            long stop = (at.hasStop()) ? at.getStop() : zoom.stopInstant;
            int x2 = zoom.convertInstantToPixel(stop);
            if (x1 <= 0 && x2 < 0)
                continue;
            if (x1 < 0)
                x1 = 0;
            int width = (x2 - x1 <= 1) ? 1 : x2 - x1 - 1;
            big.fillRect(x1 - leftDelta, 0, width, getHeight());
            big.setColor(fgcolor);
            big.setFont(f);
            Rectangle2D bounds = f.getStringBounds(at.getName(), big.getFontRenderContext());
            if (width > bounds.getWidth()) {
                LineMetrics lm = f.getLineMetrics(at.getName(), big.getFontRenderContext());
                big.drawString(at.getName(), x1 - leftDelta + 1, (int) lm.getAscent() + 1);
            }
            big.setColor(Color.DARK_GRAY);
            big.drawRect(x1 - leftDelta, 0, width - 1, getHeight() - 1);
        }
    // border.paintBorder(this, big, 0, 0, getWidth(),getHeight() );
    }
    g.drawImage(image, 0, 0, this);
}
Also used : Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) LineMetrics(java.awt.font.LineMetrics) RGB(org.eclipse.swt.graphics.RGB) BufferedImage(java.awt.image.BufferedImage) ArchiveTag(org.yamcs.protobuf.Yamcs.ArchiveTag) Graphics2D(java.awt.Graphics2D)

Example 3 with ArchiveTag

use of org.yamcs.protobuf.Yamcs.ArchiveTag in project yamcs-studio by yamcs.

the class TagTimeline method time2Tag.

static int time2Tag(List<ArchiveTag> tagList, long t) {
    int min = 0;
    int max = tagList.size() - 1;
    int mid;
    while (min <= max) {
        mid = (min + max) >> 1;
        ArchiveTag atmid = tagList.get(mid);
        if (!atmid.hasStart() || atmid.getStart() <= t) {
            if (!atmid.hasStop() || atmid.getStop() >= t) {
                return mid;
            } else {
                min = mid + 1;
            }
        } else {
            max = mid - 1;
        }
    }
    return -1;
}
Also used : ArchiveTag(org.yamcs.protobuf.Yamcs.ArchiveTag)

Example 4 with ArchiveTag

use of org.yamcs.protobuf.Yamcs.ArchiveTag in project yamcs-studio by yamcs.

the class TagBox method redrawTags.

void redrawTags() {
    // Draw reverse, so that 'most' tags stick to scale
    removeAll();
    if (!tags.isEmpty()) {
        int row = tags.size() - 1;
        Insets in = this.getInsets();
        for (ListIterator<List<ArchiveTag>> it = tags.listIterator(tags.size()); it.hasPrevious(); ) {
            List<ArchiveTag> lat = it.previous();
            TagTimeline tt = new TagTimeline(this, lat, zoom, row--, in.left);
            add(tt);
        }
    }
    revalidate();
    repaint();
}
Also used : Insets(java.awt.Insets) ArrayList(java.util.ArrayList) List(java.util.List) ArchiveTag(org.yamcs.protobuf.Yamcs.ArchiveTag)

Example 5 with ArchiveTag

use of org.yamcs.protobuf.Yamcs.ArchiveTag in project yamcs-studio by yamcs.

the class TagBox method insertTag.

/**
 * insert a tag in tags, in order ensuring no overlap.
 *
 * @param tag
 */
private void insertTag(ArchiveTag tag) {
    boolean inserted = false;
    for (List<ArchiveTag> atl : tags) {
        int min = 0, max = atl.size() - 1;
        while (min <= max) {
            int mid = (min + max) >> 1;
            ArchiveTag midtag = atl.get(mid);
            if (tag.hasStop() && midtag.hasStart() && tag.getStop() < midtag.getStart()) {
                max = mid - 1;
            } else if (tag.hasStart() && midtag.hasStop() && tag.getStart() > midtag.getStop()) {
                min = mid + 1;
            } else {
                // overlap
                break;
            }
        }
        if (min > max) {
            atl.add(min, tag);
            inserted = true;
            break;
        }
    }
    if (!inserted) {
        List<ArchiveTag> atl = new ArrayList<>();
        atl.add(tag);
        tags.add(atl);
    }
}
Also used : ArrayList(java.util.ArrayList) ArchiveTag(org.yamcs.protobuf.Yamcs.ArchiveTag)

Aggregations

ArchiveTag (org.yamcs.protobuf.Yamcs.ArchiveTag)7 ArrayList (java.util.ArrayList)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Insets (java.awt.Insets)1 LineMetrics (java.awt.font.LineMetrics)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 List (java.util.List)1 Box (javax.swing.Box)1 JLabel (javax.swing.JLabel)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 RGB (org.eclipse.swt.graphics.RGB)1 CreateTagRequest (org.yamcs.protobuf.Rest.CreateTagRequest)1 ArchiveCatalogue (org.yamcs.studio.core.model.ArchiveCatalogue)1