Example #1
0
 public void setSelectedFont(Font font) {
   selectedFont = font;
   family = font.getFamily();
   style = font.getStyle();
   size = font.getSize();
   preview.setFont(font);
 }
Example #2
0
 /**
  * Create the name label if needed.
  *
  * @return The component that holds the name label.
  */
 protected JComponent getLabelComponent() {
   if (nameLabel == null) {
     nameLabel = new JLabel();
     Font font = nameLabel.getFont();
     nameLabel.setFont(font.deriveFont(Font.ITALIC | Font.BOLD));
     labelComponent = GuiUtils.hflow(Misc.newList(new JLabel("Layout Model: "), nameLabel));
   }
   return labelComponent;
 }
Example #3
0
  /**
   * Create, if needed, and return the component label
   *
   * @return component label
   */
  protected JLabel doMakeDisplayLabel() {
    if (displayLabel == null) {
      displayLabel = GuiUtils.cLabel(getName());

      Font f = displayLabel.getFont();
      f = f.deriveFont(18.0f);
      displayLabel.setFont(f);
      if (!labelShown) {
        displayLabel.setVisible(false);
      }
    }
    return displayLabel;
  }
  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);
      }
    }
  }
  /**
   * If the font is set to null, then the font used to display today's date as text will default to
   * the L&amp;F's Label default font.
   *
   * <p>Otherwise, the font used to display today's date is set as given.
   *
   * @param font The font to set.
   */
  public void setTodayFont(Font font) {
    if (font == null && todayFont != null || !font.equals(todayFont)) {

      todayFont = font;
      if (isDisplayable()) setupTodayFont();
    }
  }
  /**
   * If the font is set to null, then the day font will default to 9/11th's of the L&amp;F's Button
   * default font.
   *
   * <p>Otherwise, the day font is set as given.
   *
   * @param font The font to set.
   */
  public void setDayFont(Font font) {
    if (font == null && dayFont != null || !font.equals(dayFont)) {

      dayFont = font;
      if (isDisplayable()) setupDayFonts();
    }
  }
  /**
   * If the font is set to null, then the title font (for the Month Year title) will default to the
   * L&amp;F's Label default font.
   *
   * <p>Otherwise, the title font is set as given.
   *
   * @param font The font to set.
   */
  public void setTitleFont(Font font) {
    if (font == null && titleFont != null || !font.equals(titleFont)) {

      titleFont = font;
      if (isDisplayable()) setupTitleFont();
    }
  }
Example #8
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;
 }
  /** Set the day-of-week labels' font. */
  protected void setupDayOfWeekFonts() {
    Font font;
    if (dayOfWeekLabels == null) return;

    // If not null, use what the user gave us

    font = dayOfWeekFont;

    // Otherwise, use 9/11 of the L&F default for a label

    if (font == null) {
      font = UIManager.getFont("Label.font");
      font = font.deriveFont((float) (font.getSize2D() * 9.0 / 11.0));
    }

    // Set the day of week labels' font

    for (int day = 0; day < 7; day++) {
      dayOfWeekLabels[day].setFont(font);
    }
  }
Example #10
0
 public void changeFont() {
   font = DisplayOptions.getFont(fontName, fontStyle, fontSize);
   setFont(font);
   fontH = font.getSize();
   rHeight = fontH;
   if (!inEditMode) {
     if ((curDim.height > 0) && (rHeight > curDim.height)) {
       adjustFont(curDim.width, curDim.height);
     }
   }
   repaint();
 }
  /** Set the day labels' font. */
  protected void setupDayFonts() {
    Font font;
    if (dayButtons == null) return;

    // If null, use what the user gave us

    font = dayFont;

    // Otherwise, use 9/11 of the L&F default for a button

    if (font == null) {
      font = UIManager.getFont("Button.font");
      font = font.deriveFont((float) (font.getSize2D() * 9.0 / 11.0));
    }

    // Set the day labels' font

    for (int row = 0; row < 6; row++) {
      for (int day = 0; day < 7; day++) {
        dayButtons[row][day].setFont(font);
      }
    }
  }
Example #12
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);
  }
Example #13
0
 public void setEditMode(boolean s) {
   if (s) {
     addMouseListener(ml);
     setOpaque(s);
     if (font != null) {
       setFont(font);
       fontH = font.getSize();
       rHeight = fontH;
     }
     defDim = getPreferredSize();
     curLoc.x = defLoc.x;
     curLoc.y = defLoc.y;
     curDim.width = defDim.width;
     curDim.height = defDim.height;
     xRatio = 1.0;
     yRatio = 1.0;
   } else {
     removeMouseListener(ml);
     if ((bg != null) || (isActive < 1)) setOpaque(true);
     else setOpaque(false);
   }
   inEditMode = s;
 }
Example #14
0
  private void init(Font font) {
    JPanel content = new JPanel(new BorderLayout());
    content.setBorder(new EmptyBorder(12, 12, 12, 12));
    setContentPane(content);

    JPanel listPanel = new JPanel(new GridLayout(1, 3, 6, 6));

    String[] fonts;
    try {
      fonts = getFontList();
    } catch (Exception e) {
      Log.log(Log.ERROR, this, "Broken Java implementation!");

      Log.log(Log.ERROR, this, e);

      fonts = new String[] {"Broken Java implementation!"};
    }

    JPanel familyPanel =
        createTextFieldAndListPanel(
            "font-selector.family", familyField = new JTextField(), familyList = new JList(fonts));
    listPanel.add(familyPanel);

    String[] sizes = {"9", "10", "12", "14", "16", "18", "24"};
    JPanel sizePanel =
        createTextFieldAndListPanel(
            "font-selector.size", sizeField = new JTextField(), sizeList = new JList(sizes));
    listPanel.add(sizePanel);

    String[] styles = {
      jEdit.getProperty("font-selector.plain"),
      jEdit.getProperty("font-selector.bold"),
      jEdit.getProperty("font-selector.italic"),
      jEdit.getProperty("font-selector.bolditalic")
    };

    JPanel stylePanel =
        createTextFieldAndListPanel(
            "font-selector.style", styleField = new JTextField(), styleList = new JList(styles));
    styleField.setEditable(false);
    listPanel.add(stylePanel);

    familyList.setSelectedValue(font.getFamily(), true);
    familyField.setText(font.getFamily());
    sizeList.setSelectedValue(String.valueOf(font.getSize()), true);
    sizeField.setText(String.valueOf(font.getSize()));
    styleList.setSelectedIndex(font.getStyle());
    styleField.setText((String) styleList.getSelectedValue());

    ListHandler listHandler = new ListHandler();
    familyList.addListSelectionListener(listHandler);
    sizeList.addListSelectionListener(listHandler);
    styleList.addListSelectionListener(listHandler);

    content.add(BorderLayout.NORTH, listPanel);

    preview =
        new JLabel(jEdit.getProperty("font-selector.long-text")) {
          public void paintComponent(Graphics g) {
            if (fontSelector != null) fontSelector.setAntiAliasEnabled(g);
            super.paintComponent(g);
          }
        };
    preview.setBorder(new TitledBorder(jEdit.getProperty("font-selector.preview")));

    updatePreview();

    Dimension prefSize = preview.getPreferredSize();
    prefSize.height = 50;
    preview.setPreferredSize(prefSize);

    content.add(BorderLayout.CENTER, preview);

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    buttons.setBorder(new EmptyBorder(12, 0, 0, 0));
    buttons.add(Box.createGlue());

    ok = new JButton(jEdit.getProperty("common.ok"));
    ok.addActionListener(new ActionHandler());
    getRootPane().setDefaultButton(ok);
    buttons.add(ok);

    buttons.add(Box.createHorizontalStrut(6));

    cancel = new JButton(jEdit.getProperty("common.cancel"));
    cancel.addActionListener(new ActionHandler());
    buttons.add(cancel);

    buttons.add(Box.createGlue());

    content.add(BorderLayout.SOUTH, buttons);

    pack();
    setLocationRelativeTo(getParent());
    setVisible(true);
  }
Example #15
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());
 }
Example #16
0
  public EditorPaneHTMLHelp(String htmlFile) {
    if (GlobalValues.useSystemBrowserForHelp) {
      Desktop d = GlobalValues.desktop;
      try {
        // create a temp file
        GlobalValues.forHTMLHelptempFile = new File("tempHTMLHelpSynthetic.html");
        FileWriter fw = new FileWriter(GlobalValues.forHTMLHelptempFile);

        java.util.List<String> list = readTextFromJar(htmlFile);
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
          fw.write(it.next() + "\n");
        }

        String canonicalPathOfFile = GlobalValues.forHTMLHelptempFile.getCanonicalPath();
        URL urlFile = new URL("file://" + canonicalPathOfFile);
        URI uriOfFile = urlFile.toURI();

        fw.close();

        d.browse(uriOfFile);

      } catch (Exception e) {
        e.printStackTrace();
      }

    } else {
      URL initialURL = getClass().getResource(htmlFile);

      font = GlobalValues.htmlfont;

      String title = "HTML Help";
      setTitle(title);

      final Stack<String> urlStack = new Stack<String>();
      final JEditorPane editorPane;

      editorPane = new JEditorPane(new HTMLEditorKit().getContentType(), " ");

      editorPane.setOpaque(false);
      editorPane.setBorder(null);
      editorPane.setEditable(false);

      JPanel magPanel = new JPanel();

      magnificationFactor = GlobalValues.helpMagnificationFactor;
      magFactor = new JTextField(Double.toString(magnificationFactor));

      JButton magButton = new JButton("Set Magnification: ");
      magButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              magnificationFactor = Double.parseDouble(magFactor.getText());
              GlobalValues.helpMagnificationFactor = magnificationFactor;
            }
          });

      magPanel.setLayout(new GridLayout(1, 2));
      magPanel.add(magButton);
      magPanel.add(magFactor);

      final JTextField url = new JTextField(initialURL.toString());

      // set up hyperlink listener
      editorPane.setEditable(false);

      try {
        // remember URL for back button
        urlStack.push(initialURL.toString());
        // show URL in text field
        url.setText(initialURL.toString());

        // add a CSS rule to force body tags to use the default label font
        // instead of the value in javax.swing.text.html.default.csss

        String bodyRule =
            "body { font-family: "
                + font.getFamily()
                + "; "
                + "font-size: "
                + font.getSize() * GlobalValues.helpMagnificationFactor
                + "pt; }";
        ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule);

        editorPane.setPage(initialURL);

        editorPane.firePropertyChange("dummyProp", true, false);

      } catch (IOException e) {
        editorPane.setText("Exception: " + e);
      }

      editorPane.addPropertyChangeListener(
          new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {

              String bodyRule =
                  "body { font-family: "
                      + font.getFamily()
                      + "; "
                      + "font-size: "
                      + font.getSize() * GlobalValues.helpMagnificationFactor
                      + "pt; }";
              ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule);
            }
          });

      editorPane.addHyperlinkListener(
          new HyperlinkListener() {
            public void hyperlinkUpdate(HyperlinkEvent event) {
              if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                  // remember URL for back button
                  urlStack.push(event.getURL().toString());
                  // show URL in text field
                  url.setText(event.getURL().toString());
                  editorPane.setPage(event.getURL());

                  editorPane.firePropertyChange("dummyProp", true, false);

                } catch (IOException e) {
                  editorPane.setText("Exception: " + e);
                }
              }
            }
          });

      // set up checkbox for toggling edit mode
      final JCheckBox editable = new JCheckBox();
      editable.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              editorPane.setEditable(editable.isSelected());
            }
          });

      // set up load button for loading URL
      ActionListener listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              try {
                // remember URL for back button
                urlStack.push(url.getText());
                editorPane.setPage(url.getText());

                editorPane.firePropertyChange("dummyProp", true, false);

              } catch (IOException e) {
                editorPane.setText("Exception: " + e);
              }
            }
          };

      JButton loadButton = new JButton("Load/Magnify");
      loadButton.addActionListener(listener);
      url.addActionListener(listener);

      // set up back button and button action

      JButton backButton = new JButton("Back");
      backButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              if (urlStack.size() <= 1) return;
              try {
                // get URL from back button
                urlStack.pop();
                // show URL in text field
                String urlString = urlStack.peek();
                url.setText(urlString);
                editorPane.setPage(urlString);

                editorPane.firePropertyChange("dummyProp", true, false);

              } catch (IOException e) {
                editorPane.setText("Exception: " + e);
              }
            }
          });

      JPanel allPanel = new JPanel(new BorderLayout());

      // put all control components in a panel

      JPanel ctrlPanel = new JPanel(new BorderLayout());
      JPanel urlPanel = new JPanel();
      urlPanel.add(new JLabel("URL"));
      urlPanel.add(url);
      JPanel buttonPanel = new JPanel();
      buttonPanel.add(loadButton);
      buttonPanel.add(backButton);
      buttonPanel.add(new JLabel("Editable"));
      buttonPanel.add(magPanel);
      buttonPanel.add(editable);
      ctrlPanel.add(buttonPanel, BorderLayout.NORTH);
      ctrlPanel.add(urlPanel, BorderLayout.CENTER);

      allPanel.add(ctrlPanel, BorderLayout.NORTH);
      allPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER);

      add(allPanel);
    }
  }