/**
  * {@inheritDoc}
  *
  * <p>Paints a diagonal cross over the text if the comp is of type JLabel, does nothing otherwise.
  */
 @Override
 protected void doPaint(Graphics2D g, JComponent comp, int width, int height) {
   if (!(comp instanceof JLabel)) return;
   JLabel label = (JLabel) comp;
   Insets insets = label.getInsets(insetss);
   paintViewR.x = insets.left;
   paintViewR.y = insets.top;
   paintViewR.width = width - (insets.left + insets.right);
   paintViewR.height = height - (insets.top + insets.bottom);
   paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
   paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
   SwingUtilities.layoutCompoundLabel(
       label,
       label.getFontMetrics(label.getFont()),
       label.getText(),
       null,
       label.getVerticalAlignment(),
       label.getHorizontalAlignment(),
       label.getVerticalTextPosition(),
       label.getHorizontalTextPosition(),
       paintViewR,
       paintIconR,
       paintTextR,
       label.getIconTextGap());
   doPaint(g, paintTextR);
 }
  /** Constructs this CytoPanel. */
  private void constructPanel() {
    // init our components
    initLabel();
    initButtons();

    // add label and button components to yet another panel,
    // so we can layout properly
    final JPanel floatDockPanel = new JPanel();
    final BoxLayout boxLayout = new BoxLayout(floatDockPanel, BoxLayout.X_AXIS);
    floatDockPanel.setLayout(boxLayout);

    floatDockPanel.add(Box.createHorizontalStrut(8));
    floatDockPanel.add(floatLabel);
    floatDockPanel.add(Box.createHorizontalGlue());
    floatDockPanel.add(floatButton);
    floatDockPanel.add(closeButton);
    floatDockPanel.add(Box.createHorizontalStrut(8));

    // set preferred size - we can use float or dock icon dimensions - they are the same
    final FontMetrics fm = floatLabel.getFontMetrics(floatLabel.getFont());
    floatDockPanel.setMinimumSize(
        new Dimension(
            (fm.stringWidth(getTitle()) + BUTTON_SIZE) * FLOAT_PANEL_SCALE_FACTOR, BUTTON_SIZE));
    floatDockPanel.setPreferredSize(
        new Dimension(
            (fm.stringWidth(getTitle()) + BUTTON_SIZE) * FLOAT_PANEL_SCALE_FACTOR,
            BUTTON_SIZE + 10));

    // use the border layout for this CytoPanel
    setLayout(new BorderLayout());
    add(floatDockPanel, BorderLayout.NORTH);
    add(tabbedPane, BorderLayout.CENTER);
  }
Example #3
0
 public void propertiesChanged() {
   // retarded GTK look and feel!
   Font font = new JLabel().getFont();
   // UIManager.getFont("Label.font");
   FontMetrics fm = wrap.getFontMetrics(font);
   Dimension dim =
       new Dimension(
           Math.max(Math.max(fm.charWidth('-'), fm.charWidth('H')), fm.charWidth('S')) + 1,
           fm.getHeight());
   wrap.setPreferredSize(dim);
   wrap.setMaximumSize(dim);
 }
  private static String splitText(final JLabel label, final String text, final int widthLimit) {
    final FontMetrics fontMetrics = label.getFontMetrics(label.getFont());

    final String[] lines = UIUtil.splitText(text, fontMetrics, widthLimit, ' ');

    final StringBuilder result = new StringBuilder();
    for (int i = 0; i < lines.length; i++) {
      final String line = lines[i];
      if (i > 0) {
        result.append('\n');
      }
      result.append(line);
    }
    return result.toString();
  }
Example #5
0
 /** Set the label text. */
 private void setLabelText() {
   if (!active) {
     return;
   }
   StringBuffer buf = new StringBuffer();
   buf.append(" ");
   buf.append(getRangeName());
   buf.append(": ");
   buf.append(StringUtil.padLeft(rangeReadout.getNumericString(), 6));
   buf.append(" ");
   buf.append(getBearingName());
   buf.append(": ");
   buf.append(StringUtil.padLeft(bearingReadout.getNumericString(), 6));
   String text = buf.toString();
   valueDisplay.setText(text);
   if (myOwnLabel) {
     FontMetrics fm = valueDisplay.getFontMetrics(valueDisplay.getFont());
     valueDisplay.setPreferredSize(new Dimension(fm.stringWidth(text), fm.getHeight()));
   }
 }
Example #6
0
  private static int getLabelBaseline(JLabel label, int height) {
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
    FontMetrics fm = label.getFontMetrics(label.getFont());

    resetRects(label, height);

    SwingUtilities.layoutCompoundLabel(
        label,
        fm,
        "a",
        icon,
        label.getVerticalAlignment(),
        label.getHorizontalAlignment(),
        label.getVerticalTextPosition(),
        label.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        label.getIconTextGap());

    return textRect.y + fm.getAscent();
  }
  /**
   * Computes the maximum width of a label in the configuration form.
   *
   * @param configForm the configuration form containing all labels.
   * @return the maximum width of a label in the configuration form
   */
  private int computeLabelWidth(ChatRoomConfigurationForm configForm) {
    int labelWidth = 0;

    Iterator<ChatRoomConfigurationFormField> configurationSet = configForm.getConfigurationSet();

    while (configurationSet.hasNext()) {
      ChatRoomConfigurationFormField formField = configurationSet.next();

      if (formField.getLabel() == null) continue;

      JLabel label = new JLabel(formField.getLabel());

      int newLabelWidth =
          SwingUtilities.computeStringWidth(
              label.getFontMetrics(label.getFont()), formField.getLabel());

      if (newLabelWidth > labelWidth) labelWidth = newLabelWidth;
    }

    // We add 10 pixels to be sure that even after adding the ':' char
    // the label will rest visible.
    return labelWidth + 10;
  }
 public XFInputDialogField(
     String fieldCaption, String inputType, String parmID, XFInputDialog dialog) {
   super();
   parmID_ = parmID;
   if (!inputType.equals("ALPHA")
       && !inputType.equals("KANJI")
       && !inputType.equals("NUMERIC")
       && !inputType.equals("DATE")
       && !inputType.equals("LISTBOX")
       && !inputType.equals("CHECKBOX")) {
     inputType_ = "ALPHA";
   }
   inputType_ = inputType;
   dialog_ = dialog;
   jLabelField.setText(fieldCaption + " ");
   jLabelField.setFocusable(false);
   jLabelField.setHorizontalAlignment(SwingConstants.RIGHT);
   jLabelField.setVerticalAlignment(SwingConstants.TOP);
   jLabelField.setFont(new java.awt.Font("Dialog", 0, 14));
   metrics = jLabelField.getFontMetrics(new java.awt.Font("Dialog", 0, 14));
   jLabelField.setPreferredSize(new Dimension(120, XFUtility.FIELD_UNIT_HEIGHT));
   if (metrics.stringWidth(fieldCaption) > 120) {
     jLabelField.setFont(new java.awt.Font("Dialog", 0, 12));
     metrics = jLabelField.getFontMetrics(new java.awt.Font("Dialog", 0, 12));
     if (metrics.stringWidth(fieldCaption) > 120) {
       jLabelField.setFont(new java.awt.Font("Dialog", 0, 10));
     }
   }
   if (inputType_.equals("ALPHA") || inputType_.equals("KANJI") || inputType_.equals("NUMERIC")) {
     JTextField field = new JTextField();
     field.addFocusListener(new ComponentFocusListener());
     if (inputType_.equals("NUMERIC")) {
       field.setHorizontalAlignment(SwingConstants.RIGHT);
       field.setDocument(new LimitedDocument(this));
     }
     component = field;
   }
   if (inputType_.equals("DATE")) {
     XFDateField field = new XFDateField(dialog_.getSession());
     component = field;
   }
   if (inputType_.equals("LISTBOX")) {
     JComboBox field = new JComboBox();
     component = field;
   }
   if (inputType_.equals("CHECKBOX")) {
     JCheckBox field = new JCheckBox();
     component = field;
   }
   component.setFont(new java.awt.Font("Monospaced", 0, 14));
   metrics = component.getFontMetrics(new java.awt.Font("Monospaced", 0, 14));
   this.setOpaque(false);
   if (inputType_.equals("DATE")) {
     int fieldWidth = XFUtility.getWidthOfDateValue(dialog_.getSession().getDateFormat(), 14);
     this.setBounds(
         this.getBounds().x, this.getBounds().y, 150 + fieldWidth, XFUtility.FIELD_UNIT_HEIGHT);
   } else {
     this.setBounds(this.getBounds().x, this.getBounds().y, 150, XFUtility.FIELD_UNIT_HEIGHT);
   }
   this.setLayout(new BorderLayout());
   this.add(jLabelField, BorderLayout.WEST);
   this.add(component, BorderLayout.CENTER);
 }
Example #9
0
 private TextInBox newNode(String nome) {
   JLabel label = new JLabel();
   label.setText(nome);
   FontMetrics tamanho = label.getFontMetrics(label.getFont());
   return new TextInBox(nome, tamanho.stringWidth(nome) + 8, 20);
 }
  public void initialize(ISocialManager manager, Sheet sheet, Role role) {
    this.manager = manager;
    this.sheet = sheet;
    int maxLessonTokens = ((TokenSheet) sheet.getDetails()).getMaxLessonTokens();
    int maxStudents = ((TokenSheet) sheet.getDetails()).getMaxStudents();
    this.maxLessonLimit = maxLessonTokens * maxStudents;
    this.maxUnitLimit = ((TokenSheet) sheet.getDetails()).getMaxUnitTokens();

    String currentLesson = null;
    try {
      currentLesson = manager.getCurrentInstance().getLesson().getId();
    } catch (IOException ex) {
      Logger.getLogger(StudentUnitTokenView.class.getName()).log(Level.SEVERE, null, ex);
    }
    manager.addResultListener(sheet.getId(), this);
    try {

      // Add the current lesson results in the view.
      GridLayout gl = (GridLayout) getLayout();
      currentLessonPanel = new TokenStudentPanel(manager, sheet);
      String lessonName = manager.getCurrentInstance().getLesson().getName();
      currentLabel = new JLabel(currentLessonPanel.getImageIcon());
      currentLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18));
      currentLabel.setHorizontalTextPosition(JLabel.CENTER);
      currentLabel.setText(lessonName);

      int lessonNameWidth =
          currentLabel.getFontMetrics(currentLabel.getFont()).stringWidth(lessonName) + 15;
      if (role != Role.STUDENT) {
        rows++;
        gl.setRows(rows);
        this.add(currentLabel);
        this.setPreferredSize(
            new Dimension(
                currentLessonPanel.getImageIcon().getIconWidth(),
                currentLessonPanel.getImageIcon().getIconHeight() * rows));
        //                List<Sheet> sheets = manager.getCurrentInstance().getSheets();
        //                for (Sheet sheet1 : sheets) {
        //                    if (sheet1.getDetails() instanceof TokenSheet) {
        //                        Collection<Result> results = manager.getResults(sheet1.getId());
        //                        Result myResult = null;
        //                        for (Result result : results) {
        //                            if (result.getCreator().equals(manager.getUsername())) {
        //                                myResult = result;
        //                                currentLessonPanel.updateStudentTokens((TokenResult)
        // result.getDetails());
        //                            }
        //                        }
        //                        if (myResult != null) {
        //                            results.remove(myResult);
        //                        }
        //
        //                    }
        //                }
        ArrayList<Result> results = (ArrayList<Result>) manager.getResults(sheet.getId());
        sortAndDisplayTokens(results, currentLessonPanel, maxLessonLimit);
      }

      // Add the unit tokens view.

      unitPanel = new TokenStudentPanel(manager, sheet);
      rows++;
      gl.setRows(rows);
      String unitName = manager.getCurrentInstance().getUnit().getName();
      unitLabel = new JLabel(unitPanel.getImageIcon());
      unitLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18));
      unitLabel.setHorizontalTextPosition(JLabel.CENTER);
      unitLabel.setText(unitName);

      int unitNameWidth = unitLabel.getFontMetrics(unitLabel.getFont()).stringWidth(unitName) + 15;
      this.add(unitLabel);
      this.setPreferredSize(
          new Dimension(
              unitPanel.getImageIcon().getIconWidth(),
              unitPanel.getImageIcon().getIconHeight() * rows));
      ArrayList<Result> unitTokenResults =
          (ArrayList<Result>) manager.getCurrentUnitResults(sheet.getDetails());
      sortAndDisplayTokens(unitTokenResults, unitPanel, maxUnitLimit);
    } catch (IOException ex) {
      Logger.getLogger(StudentUnitTokenView.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Example #11
0
  /**
   * "Fixates" the preferred width of the given label to the given text.
   *
   * @param aLabel the label to fixate, cannot be <code>null</code>;
   * @param aMinimalText the text to use as minimal width indicator.
   */
  public static final void fixLabelWidth(final JLabel aLabel, final String aMinimalText) {
    final FontMetrics fm = aLabel.getFontMetrics(aLabel.getFont());
    final int height = fm.getHeight();

    aLabel.setPreferredSize(new Dimension(fm.stringWidth(aMinimalText), height));
  }
Example #12
0
  @Override
  public Component getTreeCellRendererComponent(
      JTree tree,
      Object oValue,
      boolean bSelected,
      boolean bExpanded,
      boolean bLeaf,
      int iRow,
      boolean bHasFocus) {

    final JLabel lbl =
        (JLabel)
            super.getTreeCellRendererComponent(
                tree, oValue, bSelected, bExpanded, bLeaf, iRow, bHasFocus);

    String tmp = lbl.getText();

    final List<PaintImage> images = new LinkedList<PaintImage>();

    int idx = -1;
    int spaceX = SwingUtilities.computeStringWidth(lbl.getFontMetrics(lbl.getFont()), " ");

    while ((idx = tmp.indexOf("[$" + CollectableFieldFormat.class.getName() + ",")) != -1) {
      int formatEnd = tmp.indexOf("$]");
      String format = tmp.substring(idx, formatEnd);

      String[] formatDef = format.split(",");
      try {
        CollectableFieldFormat clctformat =
            CollectableFieldFormat.getInstance(Class.forName(formatDef[1]));

        int x =
            SwingUtilities.computeStringWidth(
                lbl.getFontMetrics(lbl.getFont()), tmp.substring(0, idx));

        NuclosImage img = (NuclosImage) clctformat.parse(null, formatDef[3]);

        String tmp1 = tmp.substring(0, idx);
        for (int i = 0; i < img.getWidth() / spaceX; i++) {
          tmp1 += " ";
        }
        tmp1 += tmp.substring(formatEnd + 2);
        tmp = tmp1;

        images.add(new PaintImage(x, img));
      } catch (CollectableFieldFormatException e) {
        LOG.error("format exception at " + formatDef[1], e);
      } catch (ClassNotFoundException e) {
        LOG.error("class not found for " + formatDef[1], e);
      }
    }

    final ExplorerNode<?> explorernode = (ExplorerNode<?>) oValue;

    DefaultTreeCellRenderer lbComp =
        new DefaultTreeCellRenderer() {

          private static final long serialVersionUID = 5423600039963175923L;

          public void paintComponent(java.awt.Graphics g) {
            super.paintComponent(g);

            Graphics2D g2d = (Graphics2D) g;
            for (PaintImage paintImage : images) {
              g2d.drawImage(
                  new ImageIcon(paintImage.image.getContent()).getImage(),
                  getIcon().getIconWidth() + getIconTextGap() + paintImage.x,
                  1,
                  null);
            }
          };
        };

    JComponent result =
        (JComponent)
            lbComp.getTreeCellRendererComponent(
                tree, oValue, bSelected, bExpanded, bLeaf, iRow, bHasFocus);

    lbComp.setText(tmp);

    // set tooltip text:
    final String sDescription =
        StringUtils.nullIfEmpty(explorernode.getTreeNode().getDescription());
    lbComp.setToolTipText(sDescription);

    // set icon:
    final Icon icon = explorernode.getIcon();
    // if (icon != null) {
    lbComp.setIcon(icon);
    // }

    if (explorernode instanceof GenericObjectExplorerNode) {
      final Icon iconRelation = ((GenericObjectExplorerNode) explorernode).getRelationIcon();
      if (iconRelation != null) {
        lbComp.setIcon(new CompositeIcon(iconRelation, icon));

        // result = new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 0));
        // result.add(new JLabel(iconRelation));
        // result.add(lbl);
        // result.setOpaque(false);
      }
    }

    return result;
  }