예제 #1
0
  public void go() {
    setUpGui();

    try {

      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.open();
      // make a sequencer and open
      sequencer.addControllerEventListener(m1, new int[] {127});
      Sequence seq = new Sequence(Sequence.PPQ, 4);
      Track track = seq.createTrack();

      int r = 0;
      for (int i = 0; i < 300; i += 4) {

        r = (int) ((Math.random() * 50) + 1);
        track.add(makeEvent(144, 1, r, 100, i));
        track.add(makeEvent(176, 1, 127, 0, i));
        track.add(makeEvent(128, 1, r, 100, i + 2));
      } // end loop

      sequencer.setSequence(seq);
      sequencer.start();
      sequencer.setTempoInBPM(120);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  } // close method
예제 #2
0
    @Override
    public String getAccessibleName() {
      String name = super.getAccessibleName();

      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        String keyValueList = "";
        for (Sequence seq : seqs) {
          if (seq.isPlotted) {
            String value = "null";
            if (seq.size > 0) {
              if (unit == Unit.BYTES) {
                value = Resources.format(Messages.SIZE_BYTES, seq.value(seq.size - 1));
              } else {
                value =
                    getFormattedValue(seq.value(seq.size - 1), false)
                        + ((unit == Unit.PERCENT) ? "%" : "");
              }
            }
            // Assume format string ends with newline
            keyValueList +=
                Resources.format(Messages.PLOTTER_ACCESSIBLE_NAME_KEY_AND_VALUE, seq.key, value);
          }
        }
        name += "\n" + keyValueList + ".";
      } else {
        name += "\n" + Messages.PLOTTER_ACCESSIBLE_NAME_NO_DATA;
      }
      return name;
    }
예제 #3
0
  public void buildTrackAndStart() {
    int[] trackList = null;

    sequence.deleteTrack(track);
    track = sequence.createTrack();

    for (int i = 0; i < 16; i++) {
      trackList = new int[16];

      int key = instruments[i];

      for (int j = 0; j < 16; j++) {
        JCheckBox jc = (JCheckBox) checkboxList.get(j + (16 * i));
        if (jc.isSelected()) {
          trackList[j] = key;
        } else {
          trackList[j] = 0;
        }
      } // close inner loop

      makeTracks(trackList);
      track.add(makeEvent(176, 1, 127, 0, 16));
    } // close outer

    track.add(makeEvent(192, 9, 1, 0, 15));
    try {
      sequencer.setSequence(sequence);
      sequencer.setLoopCount(sequencer.LOOP_CONTINUOUSLY);
      sequencer.start();
      sequencer.setTempoInBPM(120);
    } catch (Exception e) {
      e.printStackTrace();
    }
  } // close buildTrackAndStart method
예제 #4
0
  public void createSequence(String key, String name, Color color, boolean isPlotted) {
    Sequence seq = getSequence(key);
    if (seq == null) {
      seq = new Sequence(key);
    }
    seq.name = name;
    seq.color = (color != null) ? color : defaultColor;
    seq.isPlotted = isPlotted;

    seqs.add(seq);
  }
예제 #5
0
  /**
   * Create one or more steps corresponding to what was done to the file dialog. If the directory is
   * non-null, the directory was changed. If the file is non-null, the file was accepted.
   */
  protected Step createFileDialogEvents(FileDialog d, String oldDir, String oldFile) {
    ComponentReference ref = getResolver().addComponent(d);
    String file = d.getFile();
    boolean accepted = file != null;
    boolean fileChanged = accepted && !file.equals(oldFile);
    String dir = d.getDirectory();
    boolean dirChanged = dir != oldDir && (dir == null || !dir.equals(oldDir));

    String desc = d.getMode() == FileDialog.SAVE ? "Save File" : "Load File";
    if (accepted) desc += " (" + file + ")";
    else desc += " (canceled)";
    Sequence seq = new Sequence(getResolver(), desc);
    if (dirChanged) {
      seq.addStep(
          new Action(
              getResolver(),
              null,
              "actionSetDirectory",
              new String[] {ref.getID(), dir},
              FileDialog.class));
    }
    if (accepted) {
      Step accept =
          new Action(
              getResolver(), null, "actionAccept", new String[] {ref.getID()}, FileDialog.class);
      if (fileChanged) {
        seq.addStep(
            new Action(
                getResolver(),
                null,
                "actionSetFile",
                new String[] {ref.getID(), file},
                FileDialog.class));
        seq.addStep(accept);
      } else {
        return accept;
      }
    } else {
      Step cancel =
          new Action(
              getResolver(), null, "actionCancel", new String[] {ref.getID()}, FileDialog.class);
      if (dirChanged) seq.addStep(cancel);
      else return cancel;
    }
    return seq;
  }
예제 #6
0
  // Called on EDT
  public void propertyChange(PropertyChangeEvent ev) {
    String prop = ev.getPropertyName();

    if (prop == JConsoleContext.CONNECTION_STATE_PROPERTY) {
      ConnectionState newState = (ConnectionState) ev.getNewValue();

      switch (newState) {
        case DISCONNECTED:
          synchronized (this) {
            long time = System.currentTimeMillis();
            times.add(time);
            for (Sequence seq : seqs) {
              seq.add(Long.MIN_VALUE);
            }
          }
          break;
      }
    }
  }
예제 #7
0
  private void saveDataToFile(File file) {
    try {
      PrintStream out = new PrintStream(new FileOutputStream(file));

      // Print header line
      out.print("Time");
      for (Sequence seq : seqs) {
        out.print("," + seq.name);
      }
      out.println();

      // Print data lines
      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        for (int i = 0; i < seqs.get(0).size; i++) {
          double excelTime = toExcelTime(times.time(i));
          out.print(String.format(Locale.ENGLISH, "%.6f", excelTime));
          for (Sequence seq : seqs) {
            out.print("," + getFormattedValue(seq.value(i), false));
          }
          out.println();
        }
      }

      out.close();
      JOptionPane.showMessageDialog(
          this,
          Resources.format(
              Messages.FILE_CHOOSER_SAVED_FILE, file.getAbsolutePath(), file.length()));
    } catch (IOException ex) {
      String msg = ex.getLocalizedMessage();
      String path = file.getAbsolutePath();
      if (msg.startsWith(path)) {
        msg = msg.substring(path.length()).trim();
      }
      JOptionPane.showMessageDialog(
          this,
          Resources.format(Messages.FILE_CHOOSER_SAVE_FAILED_MESSAGE, path, msg),
          Messages.FILE_CHOOSER_SAVE_FAILED_TITLE,
          JOptionPane.ERROR_MESSAGE);
    }
  }
예제 #8
0
  public void setUpMidi() {
    try {
      sequencer = MidiSystem.getSequencer();
      sequencer.open();
      sequence = new Sequence(Sequence.PPQ, 4);
      track = sequence.createTrack();
      sequencer.setTempoInBPM(120);

    } catch (Exception e) {
      e.printStackTrace();
    }
  } // close method
    public void actionPerformed(ActionEvent ev) {

      try {

        // make (and open) a sequencer, make a sequence and track

        Sequencer sequencer = MidiSystem.getSequencer();
        sequencer.open();

        sequencer.addControllerEventListener(myPanel, new int[] {127});
        Sequence seq = new Sequence(Sequence.PPQ, 4);
        Track track = seq.createTrack();

        // now make two midi events (containing a midi message)

        for (int i = 0; i < 100; i += 4) {

          int rNum = (int) ((Math.random() * 50) + 1);
          if (rNum < 38) { // so now only do it if num <38 (75% of the time)

            track.add(makeEvent(144, 1, rNum, 100, i));

            track.add(makeEvent(176, 1, 127, 0, i));

            track.add(makeEvent(128, 1, rNum, 100, i + 2));
          }
        } // end loop

        // add the events to the track
        // add the sequence to the sequencer, set timing, and start

        sequencer.setSequence(seq);

        sequencer.start();
        sequencer.setTempoInBPM(220);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } // close actionperformed
예제 #10
0
  public void los() {
    guiErstellen();

    try {

      // einen Sequencer erzeugen (und öffnen),
      // eine Sequence und einen Track erzeugen

      Sequencer sequencer = MidiSystem.getSequencer();
      sequencer.open();
      sequencer.addControllerEventListener(ml, new int[] {127});
      Sequence seq = new Sequence(Sequence.PPQ, 4);
      Track track = seq.createTrack();

      // jetzt werden MidiEvents (die eine
      // MidiMessage enthalten) erzeugt

      int r = 0;
      for (int i = 0; i < 60; i += 4) {
        r = (int) ((Math.random() * 50) + 1);
        track.add(eventErzeugen(144, 1, r, 100, i));
        track.add(eventErzeugen(176, 1, 127, 0, i));
        track.add(eventErzeugen(128, 1, r, 100, i + 2));
      } // Ende der for-Schleife

      // Hinzufügen der Events zum Track und der Sequence
      // zum Sequencer, Setzen der Zeiten und Starten

      sequencer.setSequence(seq);
      sequencer.start();
      sequencer.setTempoInBPM(120);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  } // Methode los schließen
예제 #11
0
  public boolean writeSequence(NoteList noteList) {

    this.noteList = noteList;

    toneMap = toneMapFrame.getToneMap();
    timeSet = toneMap.getTimeSet();
    pitchSet = toneMap.getPitchSet();
    timeRange = timeSet.getRange();
    pitchRange = pitchSet.getRange();

    if (!buildNoteSequence()) return false;

    try {
      sequence = new Sequence(Sequence.PPQ, 10);
    } catch (Exception ex) {
      ex.printStackTrace();
      return false;
    }

    track = sequence.createTrack();
    startTime = System.currentTimeMillis();

    // add a program change right at the beginning of
    // the track for the current instrument

    createEvent(PROGRAM, cc.program + 1, 1);

    for (int i = 0; i < noteSequence.size(); i++) {
      noteSequenceElement = noteSequence.get(i);
      if (noteSequenceElement.state == ON)
        if (!createEvent(NOTEON, noteSequenceElement.note, noteSequenceElement.tick)) return false;
      if (noteSequenceElement.state == OFF)
        if (!createEvent(NOTEOFF, noteSequenceElement.note, noteSequenceElement.tick)) return false;
    }
    return true;
  }
예제 #12
0
 long getLastValue(String key) {
   Sequence seq = getSequence(key);
   return (seq != null && seq.size > 0) ? seq.value(seq.size - 1) : 0L;
 }
예제 #13
0
  public void drawSequence(
      Graphics2D g,
      Sequence seq,
      int start,
      int end,
      int x1,
      int y1,
      double width,
      int height,
      boolean showScores,
      boolean displayBoxes,
      boolean displayText,
      Vector pid,
      int seqnum,
      AlignViewport av,
      Hashtable props,
      int intpid[][]) {
    LinkedHashMap conf = av.getGFFConfig();
    boolean confchanged = false;
    int length = seq.getLength();

    Color currentColor = Color.white;

    g.setColor(Color.black);

    int prevx = -1;
    int prevy = -1;

    int prevpixel = 0;

    if (!(seq instanceof GFF)) {
      return;
    }
    height -= 2;

    GFF gff = (GFF) seq;

    double minscore = gff.getMinScore();
    double maxscore = gff.getMaxScore();

    minscore = (int) (minscore - (maxscore - minscore + 1) * 0.1);
    maxscore = (int) (maxscore + (maxscore - minscore + 1) * 0.1);

    if (gff.getType().equals("Patient_Flow")) {
      minscore = 1600;
    }
    // System.out.println("Min/Max " + minscore + " " + maxscore);
    Vector feat = gff.overlaps(start, end);

    // System.out.println("Got features " + feat.size());

    int prev = -1;
    for (int i = 0; i < feat.size(); i++) {

      SequenceFeature sftmp = (SequenceFeature) feat.elementAt(i);

      int coord = sftmp.getStart();

      if (coord >= minscore) {
        Color c = Color.black;

        String key = sftmp.getType();
        if (key.indexOf("::") > 0) {
          key = key.substring(0, key.indexOf("::"));
          sftmp.setType(key);
        }
        if (conf != null && conf.containsKey(sftmp.getType())) {
          c = (Color) (conf.get(sftmp.getType()));
          g.setColor(c);
        } else {

          // c = new
          // Color((int)(Math.random()*200+50),(int)(Math.random()*200+50),(int)(Math.random()*200+50));
          c = Color.black;
          conf.put(sftmp.getType(), c);
          g.setColor(c);
          confchanged = true;
        }

        Vector tmpf = new Vector();

        if (sftmp.getFeatures() != null) {
          tmpf = sftmp.getFeatures();
        } else {
          tmpf.addElement(sftmp);
        }

        int tmpheight = height;
        double score = sftmp.getScore();

        tmpheight = (int) ((score - minscore + 1) * (height) / (maxscore - minscore + 1));

        int tmpx = x1 + (int) ((coord - start) * width) + 1;
        int tmpy = y1 + height - tmpheight + 1;

        if (prevx == -1) {
          prevx = tmpx;
          prevy = tmpy;
        }

        if (tmpx - prevx <= 2) {
          g.drawLine(prevx, prevy, tmpx, tmpy);
        }

        prevx = tmpx;
        prevy = tmpy;
      }
      i++;
    }
  }
예제 #14
0
  public double playGetLength() {

    return sequence.getMicrosecondLength();
  }
예제 #15
0
 public double getTickRate() {
   return ((double) (sequence.getResolution() * getBPM() / 60));
 }
예제 #16
0
 public void setUseDashedTransitions(String key, boolean b) {
   Sequence seq = getSequence(key);
   if (seq != null) {
     seq.transitionStroke = b ? getDashedStroke() : null;
   }
 }
예제 #17
0
 public void setIsPlotted(String key, boolean isPlotted) {
   Sequence seq = getSequence(key);
   if (seq != null) {
     seq.isPlotted = isPlotted;
   }
 }
예제 #18
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int width = getWidth() - rightMargin - leftMargin - 10;
    int height = getHeight() - topMargin - bottomMargin;
    if (width <= 0 || height <= 0) {
      // not enough room to paint anything
      return;
    }

    Color oldColor = g.getColor();
    Font oldFont = g.getFont();
    Color fg = getForeground();
    Color bg = getBackground();
    boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (smallFont == null) {
      smallFont = oldFont.deriveFont(9.0F);
    }

    r.x = leftMargin - 5;
    r.y = topMargin - 8;
    r.width = getWidth() - leftMargin - rightMargin;
    r.height = getHeight() - topMargin - bottomMargin + 16;

    if (border == null) {
      // By setting colors here, we avoid recalculating them
      // over and over.
      border =
          new BevelBorder(
              BevelBorder.LOWERED,
              getBackground().brighter().brighter(),
              getBackground().brighter(),
              getBackground().darker().darker(),
              getBackground().darker());
    }

    border.paintBorder(this, g, r.x, r.y, r.width, r.height);

    // Fill background color
    g.setColor(bgColor);
    g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);
    g.setColor(oldColor);

    long tMin = Long.MAX_VALUE;
    long tMax = Long.MIN_VALUE;
    long vMin = Long.MAX_VALUE;
    long vMax = 1;

    int w = getWidth() - rightMargin - leftMargin - 10;
    int h = getHeight() - topMargin - bottomMargin;

    if (times.size > 1) {
      tMin = Math.min(tMin, times.time(0));
      tMax = Math.max(tMax, times.time(times.size - 1));
    }
    long viewRangeMS;
    if (viewRange > 0) {
      viewRangeMS = viewRange * MINUTE;
    } else {
      // Display full time range, but no less than a minute
      viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE);
    }

    // Calculate min/max values
    for (Sequence seq : seqs) {
      if (seq.size > 0) {
        for (int i = 0; i < seq.size; i++) {
          if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) {
            long val = seq.value(i);
            if (val > Long.MIN_VALUE) {
              vMax = Math.max(vMax, val);
              vMin = Math.min(vMin, val);
            }
          }
        }
      } else {
        vMin = 0L;
      }
      if (unit == Unit.BYTES || !seq.isPlotted) {
        // We'll scale only to the first (main) value set.
        // TODO: Use a separate property for this.
        break;
      }
    }

    // Normalize scale
    vMax = normalizeMax(vMax);
    if (vMin > 0) {
      if (vMax / vMin > 4) {
        vMin = 0;
      } else {
        vMin = normalizeMin(vMin);
      }
    }

    g.setColor(fg);

    // Axes
    // Draw vertical axis
    int x = leftMargin - 18;
    int y = topMargin;
    FontMetrics fm = g.getFontMetrics();

    g.drawLine(x, y, x, y + h);

    int n = 5;
    if (("" + vMax).startsWith("2")) {
      n = 4;
    } else if (("" + vMax).startsWith("3")) {
      n = 6;
    } else if (("" + vMax).startsWith("4")) {
      n = 4;
    } else if (("" + vMax).startsWith("6")) {
      n = 6;
    } else if (("" + vMax).startsWith("7")) {
      n = 7;
    } else if (("" + vMax).startsWith("8")) {
      n = 8;
    } else if (("" + vMax).startsWith("9")) {
      n = 3;
    }

    // Ticks
    ArrayList<Long> tickValues = new ArrayList<Long>();
    tickValues.add(vMin);
    for (int i = 0; i < n; i++) {
      long v = i * vMax / n;
      if (v > vMin) {
        tickValues.add(v);
      }
    }
    tickValues.add(vMax);
    n = tickValues.size();

    String[] tickStrings = new String[n];
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      tickStrings[i] = getSizeString(v, vMax);
    }

    // Trim trailing decimal zeroes.
    if (decimals > 0) {
      boolean trimLast = true;
      boolean removedDecimalPoint = false;
      do {
        for (String str : tickStrings) {
          if (!(str.endsWith("0") || str.endsWith("."))) {
            trimLast = false;
            break;
          }
        }
        if (trimLast) {
          if (tickStrings[0].endsWith(".")) {
            removedDecimalPoint = true;
          }
          for (int i = 0; i < n; i++) {
            String str = tickStrings[i];
            tickStrings[i] = str.substring(0, str.length() - 1);
          }
        }
      } while (trimLast && !removedDecimalPoint);
    }

    // Draw ticks
    int lastY = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
      g.drawLine(x - 2, y, x + 2, y);
      String s = tickStrings[i];
      if (unit == Unit.PERCENT) {
        s += "%";
      }
      int sx = x - 6 - fm.stringWidth(s);
      if (y < lastY - 13) {
        if (checkLeftMargin(sx)) {
          // Wait for next repaint
          return;
        }
        g.drawString(s, sx, y + 4);
      }
      // Draw horizontal grid line
      g.setColor(Color.lightGray);
      g.drawLine(r.x + 4, y, r.x + r.width - 4, y);
      g.setColor(fg);
      lastY = y;
    }

    // Draw horizontal axis
    x = leftMargin;
    y = topMargin + h + 15;
    g.drawLine(x, y, x + w, y);

    long t1 = tMax;
    if (t1 <= 0L) {
      // No data yet, so draw current time
      t1 = System.currentTimeMillis();
    }
    long tz = timeDF.getTimeZone().getOffset(t1);
    long tickInterval = calculateTickInterval(w, 40, viewRangeMS);
    if (tickInterval > 3 * HOUR) {
      tickInterval = calculateTickInterval(w, 80, viewRangeMS);
    }
    long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval;
    while (t0 < viewRangeMS) {
      x = leftMargin + (int) (w * t0 / viewRangeMS);
      g.drawLine(x, y - 2, x, y + 2);

      long t = t1 - viewRangeMS + t0;
      String str = formatClockTime(t);
      g.drawString(str, x, y + 16);
      // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) {
      if ((t + tz) % (1 * DAY) == 0) {
        str = formatDate(t);
        g.drawString(str, x, y + 27);
      }
      // Draw vertical grid line
      g.setColor(Color.lightGray);
      g.drawLine(x, topMargin, x, topMargin + h);
      g.setColor(fg);
      t0 += tickInterval;
    }

    // Plot values
    int start = 0;
    int nValues = 0;
    int nLists = seqs.size();
    if (nLists > 0) {
      nValues = seqs.get(0).size;
    }
    if (nValues == 0) {
      g.setColor(oldColor);
      return;
    } else {
      Sequence seq = seqs.get(0);
      // Find starting point
      for (int p = 0; p < seq.size; p++) {
        if (times.time(p) >= tMax - viewRangeMS) {
          start = p;
          break;
        }
      }
    }

    // Optimization: collapse plot of more than four values per pixel
    int pointsPerPixel = (nValues - start) / w;
    if (pointsPerPixel < 4) {
      pointsPerPixel = 1;
    }

    // Draw graphs
    // Loop backwards over sequences because the first needs to be painted on top
    for (int i = nLists - 1; i >= 0; i--) {
      int x0 = leftMargin;
      int y0 = topMargin + h + 1;

      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Paint twice, with white and with color
        for (int pass = 0; pass < 2; pass++) {
          g.setColor((pass == 0) ? Color.white : seq.color);
          int x1 = -1;
          long v1 = -1;
          for (int p = start; p < nValues; p += pointsPerPixel) {
            // Make sure we get the last value
            if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) {
              p = nValues - 1;
            }
            int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS);
            long v2 = seq.value(p);
            if (v2 >= vMin && v2 <= vMax) {
              int y2 = (int) (h * (v2 - vMin) / (vMax - vMin));
              if (x1 >= 0 && v1 >= vMin && v1 <= vMax) {
                int y1 = (int) (h * (v1 - vMin) / (vMax - vMin));

                if (y1 == y2) {
                  // fillrect is much faster
                  g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1);
                } else {
                  Graphics2D g2d = (Graphics2D) g;
                  Stroke oldStroke = null;
                  if (seq.transitionStroke != null) {
                    oldStroke = g2d.getStroke();
                    g2d.setStroke(seq.transitionStroke);
                  }
                  g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass);
                  if (oldStroke != null) {
                    g2d.setStroke(oldStroke);
                  }
                }
              }
            }
            x1 = x2;
            v1 = v2;
          }
        }

        // Current value
        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          // a small triangle/arrow
          g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3);
        }
        g.setColor(fg);
      }
    }

    int[] valueStringSlots = new int[nLists];
    for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1;
    for (int i = 0; i < nLists; i++) {
      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Draw current value

        // TODO: collapse values if pointsPerPixel >= 4

        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i);
          g.setFont(smallFont);
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          String curValue = getFormattedValue(v, true);
          if (unit == Unit.PERCENT) {
            curValue += "%";
          }
          int valWidth = fm.stringWidth(curValue);
          String legend = (displayLegend ? seq.name : "");
          int legendWidth = fm.stringWidth(legend);
          if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) {
            // Wait for next repaint
            return;
          }
          g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10));
          g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3));

          // Maybe draw a short line to value
          if (y2 > y + 3) {
            g.drawLine(x + 9, y + 2, x + 14, y2);
          } else if (y2 < y - 3) {
            g.drawLine(x + 9, y - 2, x + 14, y2);
          }
        }
        g.setFont(oldFont);
        g.setColor(fg);
      }
    }
    g.setColor(oldColor);
  }