Exemplo n.º 1
0
 private static Font findFont(String name) {
   for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) {
     if (font.getName().equals(name)) {
       return font;
     }
   }
   return null;
 }
Exemplo n.º 2
0
  /**
   * Used to create the top panel describing the current feedback question
   *
   * @param fb Feedback question to describe
   * @return Panel with title and description
   */
  public JPanel createQuestionDataPanel(AbstractFeedbackType fb) {
    JPanel questionPanel = new JPanel();
    questionPanel.setLayout(new GridBagLayout());
    questionPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));

    GridBagConstraints leftBoxConst = new GridBagConstraints();
    leftBoxConst.anchor = GridBagConstraints.LINE_START;
    leftBoxConst.gridx = 0;
    leftBoxConst.gridy = 0;
    leftBoxConst.gridheight = 2;

    JLabel titleLabel = new JLabel(fb.getTitle());
    GridBagConstraints titleLabelConst = new GridBagConstraints();
    titleLabelConst.anchor = GridBagConstraints.CENTER;
    titleLabelConst.gridx = 1;
    titleLabelConst.gridy = 0;
    titleLabelConst.weightx = 1.0;
    Font titleLabelFont = titleLabel.getFont();
    titleLabel.setFont(
        new Font(
            titleLabelFont.getName(),
            Font.BOLD,
            titleLabelFont.getSize() + 4)); // increase label font size by 2

    JLabel descLabel = new JLabel(fb.getDescription());
    GridBagConstraints descLabelConst = new GridBagConstraints();
    descLabelConst.anchor = GridBagConstraints.CENTER;
    descLabelConst.gridx = 1;
    descLabelConst.gridy = 1;
    descLabelConst.weightx = 1.0;

    JLabel exclLabel = new JLabel("!");
    exclLabel.setAlignmentX(RIGHT_ALIGNMENT);
    exclLabel.setToolTipText("Response is mandatory");
    try {
      exclLabel.setFont(loadGlyphFont(titleLabelFont.getSize() + 4));
      exclLabel.setText("\ue101");
    } catch (FontFormatException | IOException e) {
      e.printStackTrace();
    }
    GridBagConstraints rightBoxConst = new GridBagConstraints();
    rightBoxConst.anchor = GridBagConstraints.LINE_END;
    rightBoxConst.gridx = 2;
    rightBoxConst.gridy = 0;
    rightBoxConst.gridheight = 2;
    rightBoxConst.ipadx = 4;

    questionPanel.add(new JPanel(), leftBoxConst);
    questionPanel.add(titleLabel, titleLabelConst);
    questionPanel.add(descLabel, descLabelConst);
    questionPanel.add(fb.isMandatory() ? exclLabel : new JPanel(), rightBoxConst);

    return questionPanel;
  }
Exemplo n.º 3
0
  public void loadState(UISettings object) {
    XmlSerializerUtil.copyBean(object, this);

    // Check tab placement in editor
    if (EDITOR_TAB_PLACEMENT != TABS_NONE
        && EDITOR_TAB_PLACEMENT != SwingConstants.TOP
        && EDITOR_TAB_PLACEMENT != SwingConstants.LEFT
        && EDITOR_TAB_PLACEMENT != SwingConstants.BOTTOM
        && EDITOR_TAB_PLACEMENT != SwingConstants.RIGHT) {
      EDITOR_TAB_PLACEMENT = SwingConstants.TOP;
    }

    // Check that alpha delay and ratio are valid
    if (ALPHA_MODE_DELAY < 0) {
      ALPHA_MODE_DELAY = 1500;
    }
    if (ALPHA_MODE_RATIO < 0.0f || ALPHA_MODE_RATIO > 1.0f) {
      ALPHA_MODE_RATIO = 0.5f;
    }

    setSystemFontFaceAndSize();
    // 1. Sometimes system font cannot display standard ASCII symbols. If so we have
    // find any other suitable font withing "preferred" fonts first.
    boolean fontIsValid = isValidFont(new Font(FONT_FACE, Font.PLAIN, FONT_SIZE));
    if (!fontIsValid) {
      @NonNls final String[] preferredFonts = {"dialog", "Arial", "Tahoma"};
      for (String preferredFont : preferredFonts) {
        if (isValidFont(new Font(preferredFont, Font.PLAIN, FONT_SIZE))) {
          FONT_FACE = preferredFont;
          fontIsValid = true;
          break;
        }
      }

      // 2. If all preferred fonts are not valid in current environment
      // we have to find first valid font (if any)
      if (!fontIsValid) {
        Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
        for (Font font : fonts) {
          if (isValidFont(font)) {
            FONT_FACE = font.getName();
            break;
          }
        }
      }
    }

    if (MAX_CLIPBOARD_CONTENTS <= 0) {
      MAX_CLIPBOARD_CONTENTS = 5;
    }

    fireUISettingsChanged();
  }
Exemplo n.º 4
0
  public void setFont(Font f) {
    if (f != null) {
      String str = f.getName();
      int style = f.getStyle();
      String size = "" + f.getSize();

      for (int i = 0; i < fontList.getModel().getSize(); i++) {
        String listStr = ((String) fontList.getModel().getElementAt(i)).toLowerCase();

        if (listStr.equals(str.toLowerCase())) {
          Object value = fontList.getModel().getElementAt(i);
          fontList.setSelectedValue(value, true);
          fontBox.setText((String) value);
          break;
        }
      }

      switch (style) {
        case Font.PLAIN:
          styleList.setSelectedIndex(0);
          break;
        case Font.ITALIC:
          styleList.setSelectedIndex(2);
          break;
        case Font.BOLD:
          styleList.setSelectedIndex(1);
          break;
        case Font.BOLD | Font.ITALIC:
          styleList.setSelectedIndex(3);
          break;
      }

      boolean found = false;
      for (int i = 0; i < sizeList.getModel().getSize(); i++) {
        String listStr = ((String) sizeList.getModel().getElementAt(i)).toLowerCase();

        if (listStr.equals(size.toLowerCase())) {
          Object value = sizeList.getModel().getElementAt(i);
          sizeList.setSelectedValue(value, true);
          sizeBox.setText((String) value);
          found = true;
          break;
        }
      }
      if (!found) {
        sizeBox.setText(size);
      }
    }
  }
Exemplo n.º 5
0
  private static Pair<String, Integer> getSystemFontFaceAndSize() {
    final Pair<String, Integer> fontData = UIUtil.getSystemFontData();
    if (fontData != null) {
      return fontData;
    }

    if (SystemInfo.isWindows) {
      //noinspection HardCodedStringLiteral
      final Font font =
          (Font) Toolkit.getDefaultToolkit().getDesktopProperty("win.messagebox.font");
      if (font != null) {
        return Pair.create(font.getName(), font.getSize());
      }
    }

    return Pair.create("Dialog", 12);
  }
    @Override
    public void _setTextBadge(IdeFrame frame, String text) {
      if (!isValid(frame)) {
        return;
      }

      Object icon = null;

      if (text != null) {
        try {
          int size = 55;
          BufferedImage image = UIUtil.createImage(size, size, BufferedImage.TYPE_INT_ARGB);
          Graphics2D g = image.createGraphics();

          int roundSize = 40;
          g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g.setPaint(ERROR_COLOR);
          g.fillRoundRect(
              size / 2 - roundSize / 2, size / 2 - roundSize / 2, roundSize, roundSize, size, size);

          g.setColor(Color.white);
          Font font = g.getFont();
          g.setFont(new Font(font.getName(), font.getStyle(), 22));
          FontMetrics fontMetrics = g.getFontMetrics();
          int width = fontMetrics.stringWidth(text);
          g.drawString(
              text,
              size / 2 - width / 2,
              size / 2 - fontMetrics.getHeight() / 2 + fontMetrics.getAscent());

          ByteArrayOutputStream bytes = new ByteArrayOutputStream();
          Sanselan.writeImage(image, bytes, ImageFormat.IMAGE_FORMAT_ICO, new HashMap());
          icon = Win7TaskBar.createIcon(bytes.toByteArray());
        } catch (Throwable e) {
          LOG.error(e);
        }
      }

      try {
        Win7TaskBar.setOverlayIcon(frame, icon, icon != null);
      } catch (Throwable e) {
        LOG.error(e);
      }
    }
Exemplo n.º 7
0
 public void adjustFont(int w, int h) {
   if (h <= 0) return;
   int oldH = rHeight;
   if (font == null) {
     font = getFont();
     fontH = font.getSize();
     rHeight = fontH;
   }
   nHeight = h;
   if (fontH >= h) rHeight = h - 2;
   else rHeight = fontH;
   if ((rHeight < 10) && (fontH > 10)) rHeight = 10;
   if (oldH != rHeight) {
     // Font  curFont = font.deriveFont((float) rHeight);
     Font curFont = DisplayOptions.getFont(font.getName(), font.getStyle(), rHeight);
     setFont(curFont);
   }
   if (rHeight > h) rHeight = h;
 }
Exemplo n.º 8
0
  /**
   * Update the font in the default style of the document.
   *
   * @param font the new font to use or null to remove the font attribute from the document's style
   */
  private void updateFont(Font font) {
    StyledDocument doc = (StyledDocument) getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
      return;
    }

    if (font == null) {
      style.removeAttribute(StyleConstants.FontFamily);
      style.removeAttribute(StyleConstants.FontSize);
      style.removeAttribute(StyleConstants.Bold);
      style.removeAttribute(StyleConstants.Italic);
    } else {
      StyleConstants.setFontFamily(style, font.getName());
      StyleConstants.setFontSize(style, font.getSize());
      StyleConstants.setBold(style, font.isBold());
      StyleConstants.setItalic(style, font.isItalic());
    }
  }
Exemplo n.º 9
0
  private void establishFontMetrics() {
    final BufferedImage img = createBufferedImage(1, 1);
    final Graphics2D graphics = img.createGraphics();
    graphics.setFont(myNormalFont);

    final float lineSpace = mySettingsProvider.getLineSpace();
    final FontMetrics fo = graphics.getFontMetrics();

    myDescent = fo.getDescent();
    myCharSize.width = fo.charWidth('W');
    myCharSize.height = fo.getHeight() + (int) (lineSpace * 2);
    myDescent += lineSpace;

    myMonospaced = isMonospaced(fo);
    if (!myMonospaced) {
      LOG.info("WARNING: Font " + myNormalFont.getName() + " is non-monospaced");
    }

    img.flush();
    graphics.dispose();
  }
Exemplo n.º 10
0
  private void updateText() {
    Font font = getFont();
    String styleString;
    switch (font.getStyle()) {
      case Font.PLAIN:
        styleString = jEdit.getProperty("font-selector.plain");
        break;
      case Font.BOLD:
        styleString = jEdit.getProperty("font-selector.bold");
        break;
      case Font.ITALIC:
        styleString = jEdit.getProperty("font-selector.italic");
        break;
      case Font.BOLD | Font.ITALIC:
        styleString = jEdit.getProperty("font-selector.bolditalic");
        break;
      default:
        styleString = "UNKNOWN!!!???";
        break;
    }

    setText(font.getName() + ' ' + font.getSize() + ' ' + styleString);
  }
Exemplo n.º 11
0
    public int showCustomDialog(Frame f, Font fontArg, Color foreColorArg, Color backColorArg) {
      this.setLocationRelativeTo(f);

      String s = fontArg.getName();
      fontCombo.setSelectedItem((Object) s);

      int style = fontArg.getStyle();
      if ((style & Font.ITALIC) == 0) italic.setSelected(false);
      else italic.setSelected(true);
      if ((style & Font.BOLD) == 0) bold.setSelected(false);
      else bold.setSelected(true);

      int size = fontArg.getSize();
      sizeCombo.setSelectedItem((Object) ("" + size));

      example.setFont(fontArg);
      example.setForeground(MenuBar.shapeLBG.getBackground());

      // show the dialog

      this.setVisible(true);

      return response;
    }
Exemplo n.º 12
0
 ParentDirectoryRenderer() {
   plainFont = UIManager.getFont("Tree.font");
   if (plainFont == null) plainFont = jEdit.getFontProperty("metal.secondary.font");
   boldFont = new Font(plainFont.getName(), Font.BOLD, plainFont.getSize());
 }
Exemplo n.º 13
0
  public void fillPopupMenu() {
    JMenuItem item;
    TextImageIcon textIcon;
    StatementHistory history;
    int rowCount = 0;
    int numRows = 0;
    Insets margin = new Insets(0, 0, 0, 0);

    // Get the font defined in the displayOptions panel for menus
    Font ft = DisplayOptions.getFont("Menu1");
    // We need a fairly small font, so make it 2 smaller.
    int size = ft.getSize();
    // If larger than 12, subtract 2
    if (size > 12) size -= 2;
    Font font = DisplayOptions.getFont(ft.getName(), ft.getStyle(), size);

    // This flag is used so that we only fill the menu when needed
    if (menuAlreadyFilled) return;

    menuAlreadyFilled = true;

    history = sshare.statementHistory();

    ArrayList list = history.getNamedStatementList();
    Color bgColor = Util.getBgColor();
    // Only show the Saved Statements section if there are some.
    if (list != null && list.size() != 0) {
      item = popup.add("Saved Statements");
      rowCount++;
      //	    item.setForeground(Color.blue);
      //	    item.setBackground(bgColor);
      item.setFont(font);
      item.setMargin(margin);
      popup.add(item);

      for (int i = 0; i < list.size(); i++) {
        ArrayList nameNlabel = (ArrayList) list.get(i);
        // first item in nameNlabel is name and second is label
        item = popup.add("  " + (String) nameNlabel.get(1));
        rowCount++;
        item.setActionCommand("save:" + (String) nameNlabel.get(0));
        //		item.setBackground(bgColor);
        item.addActionListener(popActionListener);
        item.setFont(font);
        item.setMargin(margin);
      }
    }
    // the rest of menu (return object types, statement types, etc.)
    ShufflerService shufflerService = sshare.shufflerService();
    ArrayList objTypes = shufflerService.getAllMenuObjectTypes();

    for (int i = 0; i < objTypes.size(); i++) {
      String objType = (String) objTypes.get(i);

      // Do not display menu for DB_AVAIL_SUB_TYPES
      if (objType.equals(Shuf.DB_AVAIL_SUB_TYPES)) continue;

      // addSeparator looks bad using GridLayout because it creates rows
      // and columns which are all equal in size.  It cannot have a row
      // with a separator which is a different height than the other
      // rectangles it creates. So just use dashes.
      item = popup.add(separator);
      item.setFont(font);
      item.setMargin(margin);
      rowCount++;
      item = popup.add(shufflerService.getCategoryLabel(objType));
      rowCount++;
      //	    item.setForeground(Color.blue);
      item.setActionCommand("title:" + objType);
      //	    item.setBackground(bgColor);
      item.addActionListener(popActionListener);
      item.setFont(font);
      item.setMargin(margin);

      ArrayList menuStrings = shufflerService.getmenuStringsThisObj(objType);

      // If current rowCount plus the next section size is too big,
      // specify the numRows to the current value of rowCount -1.
      // That is, put this next section in a new column.
      // 47 is emperical number of rows to fit 90% full screen.
      if (numRows == 0 && rowCount - 1 + menuStrings.size() > 44) {

        numRows = rowCount - 2;
      }

      for (int j = 0; j < menuStrings.size(); j++) {
        String menuString = (String) menuStrings.get(j);
        item = popup.add("  " + menuString);
        rowCount++;
        item.setActionCommand("command:" + objType + "/" + menuString);
        //		item.setBackground(bgColor);
        item.addActionListener(popActionListener);
        item.setFont(font);
        item.setMargin(margin);
      }
      // The spotter menu changes dynamically when
      // the list of saved statements changes.
      history.addStatementListener(
          new StatementAdapter() {
            public void saveListChanged() {
              refreshSaveMenu();
            }
          });
    }

    if (numRows == 0) numRows = rowCount;

    GridLayoutCol lm = new GridLayoutCol(numRows, 0);
    popup.setLayout(lm);
  }
Exemplo n.º 14
0
  protected void dolayout(String strDir, String strFreq, String strTraynum) {
    // TopBar
    String strTitle = gettitle(strFreq);
    Color color = DisplayOptions.getColor("Heading3");

    // Center Panel
    JPanel panelCenter = new JPanel(new GridBagLayout());
    GridBagConstraints gbc =
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.2,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0);
    ImageIcon icon = getImageIcon();
    // panelCenter.add(new JLabel(icon));
    addComp(panelCenter, new JLabel(icon), gbc, 0, 0);
    strTitle = getSampleName(strDir, strTraynum);
    m_lblSampleName = new JLabel(strTitle);
    if (strTitle == null || !strTitle.trim().equals("")) strTitle = "3";
    Font font = m_lblSampleName.getFont();
    font = DisplayOptions.getFont(font.getName(), Font.BOLD, 300);
    m_lblSampleName.setFont(font);
    m_lblSampleName.setForeground(color);
    // panelCenter.add(m_lblSampleName);
    m_pnlSampleName = new JPanel(new CardLayout());
    m_pnlSampleName.add(m_lblSampleName, OTHER);
    addComp(panelCenter, m_pnlSampleName, gbc, 1, 0);
    m_pnlSampleName.setVisible(false);
    m_pnlTrays = new JPanel(new GridLayout(1, 0));
    // Vast panels
    VBox pnlVast1 = new VBox(m_pnlTrays, "1");
    m_pnlTrays.add(pnlVast1);
    m_pnlVast[0] = pnlVast1;
    VBox pnlVast2 = new VBox(m_pnlTrays, "2");
    m_pnlTrays.add(pnlVast2);
    m_pnlVast[1] = pnlVast2;
    VBox pnlVast3 = new VBox(m_pnlTrays, "3");
    m_pnlTrays.add(pnlVast3);
    m_pnlVast[2] = pnlVast3;
    VBox pnlVast4 = new VBox(m_pnlTrays, "4");
    m_pnlTrays.add(pnlVast4);
    m_pnlVast[3] = pnlVast4;
    VBox pnlVast5 = new VBox(m_pnlTrays, "5");
    m_pnlTrays.add(pnlVast5);
    m_pnlVast[4] = pnlVast5;
    m_pnlSampleName.add(m_pnlTrays, VAST);

    // Login Panel
    JPanel panelThird = new JPanel(new BorderLayout());
    JPanel panelLogin = new JPanel(new GridBagLayout());
    gbc = new GridBagConstraints();
    panelThird.add(panelLogin);
    Object[] aStrUser = getOperators();
    m_cmbUser = new JComboBox(aStrUser);
    BasicComboBoxRenderer renderer = new BasicComboBoxRenderer();
    m_cmbUser.setRenderer(renderer);
    m_cmbUser.setEditable(true);
    m_passwordField = new JPasswordField();
    // *Warning, working around a Java problem*
    // When we went to the T3500 running Redhat 5.3, the JPasswordField
    // fields sometimes does not allow ANY entry of characters.  Setting
    // the enableInputMethods() to true fixed this problem.  There are
    // comments that indicate that this could cause the typed characters
    // to be visible.  I have not found that to be a problem.
    // This may not be required in the future, or could cause characters
    // to become visible in the future if Java changes it's code.
    // GRS  8/20/09
    m_passwordField.enableInputMethods(true);

    m_lblLogin = new VLoginLabel(null, "Incorrect username/password \n Please try again ", 0, 0);
    m_lblLogin.setVisible(false);
    okButton.setActionCommand("enter");
    okButton.addActionListener(this);
    cancelButton.setActionCommand("cancel");
    cancelButton.addActionListener(this);
    helpButton.setActionCommand("help");
    helpButton.addActionListener(this);
    m_passwordField.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) enterLogin();
          }
        });

    // These is some wierd problem such that sometimes, the vnmrj command
    // area gets the focus and these items in the login box do not get
    // the focus.  Even clicking in these items does not bring focus to
    // them.  Issuing requestFocus() does not bring focus to them.
    // I can however, determing if either the operator entry box or
    // the password box has focus and if neither does, I can unshow and
    // reshow the panel and that fixes the focus.  So, I have added this
    // to the mouseClicked action.  If neither has focus, it will
    // take focus with setVisible false then true.
    comboTextField = m_cmbUser.getEditor().getEditorComponent();
    m_passwordField.addMouseListener(this);
    comboTextField.addMouseListener(this);

    m_lblUsername = new JLabel(Util.getLabel("_Operator"));
    addComp(panelLogin, m_lblUsername, gbc, 0, 0);
    addComp(panelLogin, m_cmbUser, gbc, 1, 0);
    m_lblPassword = new JLabel(Util.getLabel("_Password"));
    addComp(panelLogin, m_lblPassword, gbc, 0, 1);
    addComp(panelLogin, m_passwordField, gbc, 1, 1);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.gridheight = GridBagConstraints.REMAINDER;
    addComp(panelLogin, m_lblLogin, gbc, 2, 0);
    setPref();

    Container container = getContentPane();
    JPanel panelLoginBox = new JPanel(new BorderLayout());
    panelLoginBox.add(panelCenter, BorderLayout.CENTER);
    panelLoginBox.add(panelThird, BorderLayout.SOUTH);
    container.add(panelLoginBox, BorderLayout.CENTER);
  }