/**
   * Standard constructor - builds a FontChooserPanel initialised with the specified font.
   *
   * @param font the initial font to display.
   */
  public FontChooserPanel(final Font font) {

    final GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final String[] fonts = g.getAvailableFontFamilyNames();

    setLayout(new BorderLayout());

    final JPanel leftPanel = new JPanel(new GridLayout(2, 1));
    fontlist = new JComboBox(fonts);
    adjustComponent(fontlist);
    sizelist = new JComboBox(SIZES);
    adjustComponent(sizelist);
    leftPanel.add(fontlist);
    final JPanel sizePanel = new JPanel(new BorderLayout(3, 0));
    final JLabel label = new JLabel("Size:");
    adjustComponent(label);
    label.setHorizontalAlignment(JLabel.RIGHT);
    sizePanel.add(label, BorderLayout.CENTER);
    sizePanel.add(sizelist, BorderLayout.EAST);
    leftPanel.add(sizePanel);

    final JPanel rightPanel = new JPanel(new GridLayout(2, 1));
    boldCheck = new JCheckBox("Bold");
    adjustComponent(boldCheck);
    italicCheck = new JCheckBox("Italic");
    adjustComponent(italicCheck);
    rightPanel.add(boldCheck);
    rightPanel.add(italicCheck);

    add(leftPanel, BorderLayout.CENTER);
    add(rightPanel, BorderLayout.EAST);

    setSelectedFont(font);
  }
Example #2
0
 LayerManager(Layers layers) {
   this.layers = layers;
   GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
   for (String name : gEnv.getAvailableFontFamilyNames()) log.debug(name);
   log.info("constructed");
   executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
 }
  public static void main(String[] args) throws IOException, DocumentException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontFamily = ge.getAvailableFontFamilyNames();
    PrintStream out1 = new PrintStream(new FileOutputStream(RESULT1));
    for (int i = 0; i < fontFamily.length; i++) {
      out1.println(fontFamily[i]);
    }
    out1.flush();
    out1.close();

    DefaultFontMapper mapper = new DefaultFontMapper();
    mapper.insertDirectory("c:/windows/fonts/");
    PrintStream out2 = new PrintStream(new FileOutputStream(RESULT2));
    for (Entry<String, BaseFontParameters> entry : mapper.getMapper().entrySet()) {
      out2.println(String.format("%s: %s", entry.getKey(), entry.getValue().fontName));
    }
    out2.flush();
    out2.close();

    float width = 150;
    float height = 150;
    Document document = new Document(new Rectangle(width, height));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT3));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    Graphics2D g2d = cb.createGraphics(width, height, mapper);
    for (int i = 0; i < FONTS.length; ) {
      g2d.setFont(FONTS[i++]);
      g2d.drawString("Hello world", 5, 24 * i);
    }
    g2d.dispose();
    document.close();
  }
Example #4
0
    public MyPanel(Clock clock) {
      myTime = new MyTime();
      this.clock = clock;
      font = new Font(fontStyle, fontKind, fontSize);
      super.setBackground(bgColor);
      popup = new JPopupMenu();

      JMenu mn = new JMenu("menu");
      editor = new JEditorPane();
      editor.setContentType("text/html");
      editor.setEditable(true);

      editor.setText("<b>Hello</b>");
      mn.add(editor);
      JMenu mnf = new JMenu("font style");
      JMenu mnfs = new JMenu("font size");
      JMenu mnfc = new JMenu("font color");
      JMenu mnbg = new JMenu("background color");

      mn.add(mnf);
      mn.add(mnfs);
      mn.add(mnfc);
      mn.add(mnbg);

      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      fs = ge.getAvailableFontFamilyNames();
      JMenuItem[] mif = new JMenuItem[fs.length];
      for (int i = 0; i < fs.length; i++) {
        mif[i] = new JMenuItem(fs[i]);
        mnf.add(mif[i]);
        mif[i].addActionListener(new ActionAdapter(this, this.clock));
      }

      JMenuItem[] mifs = new JMenuItem[FONT_SIZE_LENGTH];
      for (int i = 0; i < FONT_SIZE_LENGTH; i++) {
        mifs[i] = new JMenuItem(Integer.valueOf(10 * 2 * (i + 1)).toString());
        mnfs.add(mifs[i]);
        mifs[i].addActionListener(new ActionAdapter(this, this.clock));
      }

      JMenuItem[] mifc = new JMenuItem[COLOR_LIST_LENGTH];
      for (int i = 0; i < COLOR_LIST_LENGTH; i++) {
        mifc[i] = new JMenuItem(colorStr[i]);
        mnfc.add(mifc[i]);
        mifc[i].addActionListener(new ActionAdapter(this, this.clock));
      }

      JMenuItem[] mibg = new JMenuItem[COLOR_LIST_LENGTH];
      for (int i = 0; i < COLOR_LIST_LENGTH; i++) {
        mibg[i] = new JMenuItem(bgColorStr[i]);
        mnbg.add(mibg[i]);
        mibg[i].addActionListener(new ActionAdapter(this, this.clock));
      }

      popup.add(mn);
      add(popup);
    }
Example #5
0
 /**
  * Gets Label font name awaylable on current running os
  *
  * @return label font name
  */
 private static String getLabelFontName() {
   GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
   String[] names = g.getAvailableFontFamilyNames();
   Arrays.sort(names);
   if (SystemUtils.isMac() && Arrays.binarySearch(names, "Helvetica Neue") >= 0)
     return "Helvetica Neue";
   else if (Arrays.binarySearch(names, "Helvetica") >= 0) return "Helvetica";
   else if (Arrays.binarySearch(names, "Arial") >= 0) return "Arial";
   return getMonospacedFontName();
 }
  private void populateLists() {
    // Populate font names list
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] saFontNames = ge.getAvailableFontFamilyNames();
    String currentFont = ChartUIUtil.getFontName(fdCurrent);
    cmbFontNames.add(ChartUIUtil.FONT_AUTO);
    if (ChartUIUtil.FONT_AUTO.equals(currentFont)) {
      cmbFontNames.select(0);
    }
    for (int iC = 0; iC < saFontNames.length; iC++) {
      cmbFontNames.add(saFontNames[iC]);
      if (saFontNames[iC].equalsIgnoreCase(currentFont)) {
        cmbFontNames.select(iC + 1);
      }
    }
    if (cmbFontNames.getSelectionIndex() == -1) {
      cmbFontNames.select(0);
    }

    // Select alignment button
    if (isAlignmentEnabled
        && fdCurrent.getAlignment() != null
        && fdCurrent.getAlignment().isSetHorizontalAlignment()
        && fdCurrent.getAlignment().isSetVerticalAlignment()) {
      HorizontalAlignment ha = fdCurrent.getAlignment().getHorizontalAlignment();
      VerticalAlignment va = fdCurrent.getAlignment().getVerticalAlignment();
      if (HorizontalAlignment.LEFT_LITERAL.equals(ha)) {
        if (VerticalAlignment.TOP_LITERAL.equals(va)) {
          btnATopLeft.setSelection(true);
        } else if (VerticalAlignment.BOTTOM_LITERAL.equals(va)) {
          btnABottomLeft.setSelection(true);
        } else {
          btnACenterLeft.setSelection(true);
        }
      } else if (HorizontalAlignment.RIGHT_LITERAL.equals(ha)) {
        if (VerticalAlignment.TOP_LITERAL.equals(va)) {
          btnATopRight.setSelection(true);
        } else if (VerticalAlignment.BOTTOM_LITERAL.equals(va)) {
          btnABottomRight.setSelection(true);
        } else {
          btnACenterRight.setSelection(true);
        }
      } else {
        if (VerticalAlignment.TOP_LITERAL.equals(va)) {
          btnATopCenter.setSelection(true);
        } else if (VerticalAlignment.BOTTOM_LITERAL.equals(va)) {
          btnABottomCenter.setSelection(true);
        } else {
          btnACenter.setSelection(true);
        }
      }
    }
  }
Example #7
0
  static {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();
    Arrays.sort(fontNames);
    validFontNames = new ArrayList<String>(Arrays.asList(fontNames));
    int def = validFontNames.indexOf("Verdana");
    if (def > -1) defFont = def;
    else defFont = 0;

    validStyles = new ArrayList<String>();
    validStyles.add("BOLD");
    validStyles.add("ITALIC");
  }
  private void doListModels() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] allFonts = ge.getAvailableFontFamilyNames();
    // Font[]allFonts = ge.getAllFonts();
    String[] styles = {"Plain", "Bold", "Italic", "Bold Italic"};
    String[] sizes = {"8", "9", "10", "11", "12", "14", "16", "18", "20"};

    DefaultComboBoxModel fontModel = new DefaultComboBoxModel(allFonts);
    DefaultComboBoxModel styleModel = new DefaultComboBoxModel(styles);
    DefaultComboBoxModel sizeModel = new DefaultComboBoxModel(sizes);

    fontList.setModel(fontModel);
    styleList.setModel(styleModel);
    sizeList.setModel(sizeModel);
  }
Example #9
0
 /**
  * Gets Monospaced font name awailable on current running os
  *
  * @return monospaced font name
  */
 public static String getMonospacedFontName() {
   String name = null;
   GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
   String[] names = g.getAvailableFontFamilyNames();
   Arrays.sort(names);
   if (SystemUtils.isMac() && Arrays.binarySearch(names, "Tahoma") >= 0) name = "Tahoma";
   else if (Arrays.binarySearch(names, "Courier New") >= 0) name = "Courier New";
   else if (Arrays.binarySearch(names, "Courier") >= 0) name = "Courier";
   else if (Arrays.binarySearch(names, "Nimbus Mono L") >= 0) name = "Nimbus Mono L";
   else if (Arrays.binarySearch(names, "Lucida Sans Typewriter") >= 0)
     name = "Lucida Sans Typewriter";
   else if (Arrays.binarySearch(names, "Bitstream Vera Sans Mono") >= 0)
     name = "Bitstream Vera Sans Mono";
   return (name == null) ? "Terminal" : name;
 }
Example #10
0
 public textpanel() {
   GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
   String[] fontNames = env.getAvailableFontFamilyNames();
   fontBox = new JComboBox(fontNames);
   setLayout(new BorderLayout());
   JPanel fontPanel = new JPanel();
   fontPanel.add(new JLabel("Font:"));
   fontPanel.add(fontBox);
   JButton drawButton = new JButton("Draw");
   drawButton.addActionListener(this);
   fontPanel.add(drawButton);
   add(fontPanel, BorderLayout.SOUTH);
   drawingPanel = new DrawingPanel();
   fontBox.setSelectedItem("Serif");
   drawingPanel.setFontName("Serif");
   add(drawingPanel, BorderLayout.CENTER);
 }
  private void init() {
    final GraphicsEnvironment gfx = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final String[] available_fonts = gfx.getAvailableFontFamilyNames();
    // Uu.p("available fonts =");
    // Uu.p(available_fonts);
    instance_hash = new HashMap<String, Font>();

    // preload the font map with the font names as keys
    // don't add the actual font objects because that would be a waste of memory
    // we will only add them once we need to use them
    // put empty strings in instead
    available_fonts_hash = new HashMap<String, Serializable>();
    for (final String available_font : available_fonts) {
      available_fonts_hash.put(available_font, "");
    }

    // preload sans, serif, and monospace into the available font hash
    available_fonts_hash.put("Serif", new Font("Serif", Font.PLAIN, 1));
    available_fonts_hash.put("SansSerif", new Font("SansSerif", Font.PLAIN, 1));
    // Uu.p("put in sans serif");
    available_fonts_hash.put("Monospaced", new Font("Monospaced", Font.PLAIN, 1));
  }
Example #13
0
 public static Font getRandomFont(int size) {
   GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   String[] fontFamilies = ge.getAvailableFontFamilyNames();
   Random randomGenerator = new Random();
   return new Font(fontFamilies[randomGenerator.nextInt(fontFamilies.length)], Font.BOLD, size);
 }
  private JToolBar makeToolBar() {
    JToolBar tool = new JToolBar();
    tool.setFloatable(false);

    // Setup the buttons
    save.setRequestFocusEnabled(false);
    tool.add(save);
    tool.addSeparator();

    JButton button;

    button = addToolButton("GameInformationFrame.CUT"); // $NON-NLS-1$
    tool.add(button);
    button = addToolButton("GameInformationFrame.COPY"); // $NON-NLS-1$
    tool.add(button);
    button = addToolButton("GameInformationFrame.PASTE"); // $NON-NLS-1$
    tool.add(button);

    tool.addSeparator();

    button = new JButton(undoManager.getUndoAction());
    button.setText("");
    button.setToolTipText(Messages.getString("GameInformationFrame.UNDO")); // $NON-NLS-1$
    tool.add(button);
    button = new JButton(undoManager.getRedoAction());
    button.setText("");
    button.setToolTipText(Messages.getString("GameInformationFrame.REDO")); // $NON-NLS-1$
    tool.add(button);

    tool.addSeparator();

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();
    cbFonts = new JComboBox<String>(fontNames);
    cbFonts.setRequestFocusEnabled(false);
    cbFonts.setMaximumSize(cbFonts.getPreferredSize());
    cbFonts.setEditable(true);
    ActionListener lst =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (fFamilyChange) {
              fFamilyChange = false;
              return;
            }
            editor.grabFocus();
            setSelectionAttribute(StyleConstants.Family, cbFonts.getSelectedItem().toString());
          }
        };

    cbFonts.addActionListener(lst);
    tool.add(cbFonts);
    tool.addSeparator();
    sSizes = new JSpinner(new SpinnerNumberModel(12, 1, 100, 1));
    sSizes.setRequestFocusEnabled(false);
    sSizes.setMaximumSize(sSizes.getPreferredSize());
    sSizes.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent arg0) {
            if (fSizeChange) {
              fSizeChange = false;
              return;
            }
            setSelectionAttribute(StyleConstants.Size, sSizes.getValue());
            editor.grabFocus();
          }
        });
    tool.add(sSizes);
    tool.addSeparator();

    tbBold = addToggleButton("GameInformationFrame.BOLD"); // $NON-NLS-1$
    tbBold.setRequestFocusEnabled(false);
    tool.add(tbBold);
    tbItalic = addToggleButton("GameInformationFrame.ITALIC"); // $NON-NLS-1$
    tbItalic.setRequestFocusEnabled(false);
    tool.add(tbItalic);
    tbUnderline = addToggleButton("GameInformationFrame.UNDERLINE"); // $NON-NLS-1$
    tbUnderline.setRequestFocusEnabled(false);
    tool.add(tbUnderline);

    tool.addSeparator();

    tbLeft = addToggleButton("GameInformationFrame.ALIGN_LEFT"); // $NON-NLS-1$
    tbLeft.setRequestFocusEnabled(false);
    tbLeft.setSelected(true);
    tool.add(tbLeft);
    tbCenter = addToggleButton("GameInformationFrame.ALIGN_CENTER"); // $NON-NLS-1$
    tbCenter.setRequestFocusEnabled(false);
    tool.add(tbCenter);
    tbRight = addToggleButton("GameInformationFrame.ALIGN_RIGHT"); // $NON-NLS-1$
    tbRight.setRequestFocusEnabled(false);
    tool.add(tbRight);

    tool.addSeparator();

    JButton butFontColor =
        new JButton(LGM.getIconForKey("GameInformationFrame.FONTCOLOR")); // $NON-NLS-1$
    butFontColor.setRequestFocusEnabled(false);
    butFontColor.setActionCommand("GameInformationFrame.FONTCOLOR"); // $NON-NLS-1$
    butFontColor.addActionListener(this);
    butFontColor.setToolTipText(
        Messages.getString("GameInformationFrame.FONTCOLOR")); // $NON-NLS-1$
    tool.add(butFontColor);
    JButton but = new JButton(LGM.getIconForKey("GameInformationFrame.COLOR")); // $NON-NLS-1$
    but.setRequestFocusEnabled(false);
    but.setActionCommand("GameInformationFrame.COLOR"); // $NON-NLS-1$
    but.addActionListener(this);
    but.setToolTipText(Messages.getString("GameInformationFrame.COLOR")); // $NON-NLS-1$
    tool.add(but);

    return tool;
  }
 /** Returns the names of all font families available. */
 public static String[] getFontNames() {
   GraphicsEnvironment graphics;
   graphics = GraphicsEnvironment.getLocalGraphicsEnvironment();
   return graphics.getAvailableFontFamilyNames();
 }
  /** @param owner */
  WordArtCustomDialog(Frame owner) {
    super(owner, "Add Text", true);
    this.setResizable(false);
    this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontList = ge.getAvailableFontFamilyNames();
    fontCombo = new JComboBox<String>(fontList);

    italic = new JCheckBox("Italic");
    bold = new JCheckBox("Bold");

    sizeCombo = new JComboBox<String>(SZ);
    ((JLabel) sizeCombo.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
    sizeCombo.setSelectedIndex(4);
    sizeCombo.setPreferredSize(new Dimension(45, 21)); // tweek size

    example = new JTextField(" Example ");
    example.setHorizontalAlignment(SwingConstants.CENTER);
    example.setFont(new Font("sanserif", Font.PLAIN, 28));
    example.setEditable(false);

    ok = new JButton("Apply");
    cancel = new JButton("Cancel");
    ok.setPreferredSize(cancel.getPreferredSize());

    foreground = new JButton("Color");

    fontCombo.addActionListener(this);
    italic.addItemListener(this);
    bold.addItemListener(this);
    sizeCombo.addActionListener(this);
    ok.addActionListener(this);
    cancel.addActionListener(this);
    foreground.addActionListener(this);
    // custom dialog set up
    JPanel p0 = new JPanel();
    p0.add(fontCombo);
    p0.setBorder(new TitledBorder(new EtchedBorder(), "Font family"));

    JPanel p1a = new JPanel();
    p1a.add(italic);
    p1a.add(bold);
    p1a.setBorder(new TitledBorder(new EtchedBorder(), "Font style"));

    JPanel p1b = new JPanel();
    p1b.add(sizeCombo);
    p1b.add(new JLabel("pt."));
    p1b.setBorder(new TitledBorder(new EtchedBorder(), "Font size"));

    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
    p1.add(p1a);
    p1.add(p1b);
    p1.setAlignmentX(Component.CENTER_ALIGNMENT);

    JPanel p2 = new JPanel(); // use FlowLayout
    p2.add(foreground);
    p2.setBorder(new TitledBorder(new EtchedBorder(), "Message color"));
    p2.setAlignmentX(Component.CENTER_ALIGNMENT);

    JPanel p3 = new JPanel();
    p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
    p3.add(example);
    p3.setPreferredSize(new Dimension(250, 60));
    p3.setMaximumSize(new Dimension(250, 60));
    p3.setAlignmentX(Component.CENTER_ALIGNMENT);

    JPanel p4 = new JPanel();
    p4.add(ok);
    p4.add(cancel);
    p4.setAlignmentX(Component.CENTER_ALIGNMENT);

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(p0);
    p.add(Box.createRigidArea(new Dimension(0, 10)));
    p.add(p1);
    p.add(Box.createRigidArea(new Dimension(0, 10)));
    p.add(p2);
    p.add(Box.createRigidArea(new Dimension(0, 10)));
    p.add(p3);
    p.add(Box.createRigidArea(new Dimension(0, 10)));
    p.add(p4);
    p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    // tweek sizes of panels to make the dialog look nice

    Dimension d1 = p3.getPreferredSize();
    Dimension d2 = p1.getPreferredSize();
    p1.setPreferredSize(new Dimension(d1.width, d2.height));
    p1.setMaximumSize(new Dimension(d1.width, d2.height));
    d2 = p2.getPreferredSize();
    p2.setPreferredSize(new Dimension(d1.width, d2.height));
    p2.setMaximumSize(new Dimension(d1.width, d2.height));

    this.setContentPane(p);
    this.pack();
  }
Example #17
0
  public void actionPerformed(ActionEvent e) {
    JTextPane editor = (JTextPane) getEditor(e);
    int p0 = editor.getSelectionStart();
    StyledDocument doc = getStyledDocument(editor);
    Element paragraph = doc.getCharacterElement(p0);
    AttributeSet as = paragraph.getAttributes();

    family = StyleConstants.getFontFamily(as);
    fontSize = StyleConstants.getFontSize(as);

    formatText = new JDialog(new JFrame(), "Font and Size", true);
    formatText.getContentPane().setLayout(new BorderLayout());

    JPanel choosers = new JPanel();
    choosers.setLayout(new GridLayout(2, 1));

    JPanel fontFamilyPanel = new JPanel();
    fontFamilyPanel.add(new JLabel("Font"));

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();

    fontFamilyChooser = new JComboBox<String>();
    for (int i = 0; i < fontNames.length; i++) {
      fontFamilyChooser.addItem(fontNames[i]);
    }
    fontFamilyChooser.setSelectedItem(family);
    fontFamilyPanel.add(fontFamilyChooser);
    choosers.add(fontFamilyPanel);

    JPanel fontSizePanel = new JPanel();
    fontSizePanel.add(new JLabel("Size"));
    fontSizeChooser = new JComboBox<Float>();
    fontSizeChooser.setEditable(true);
    for (int size = 2; size <= 60; size += 2) {
      fontSizeChooser.addItem(new Float(size));
    }
    fontSizeChooser.setSelectedItem(new Float(fontSize));
    fontSizePanel.add(fontSizeChooser);
    choosers.add(fontSizePanel);

    JButton ok = new JButton("OK");
    ok.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            accept = true;
            formatText.dispose();
            family = (String) fontFamilyChooser.getSelectedItem();
            fontSize = Float.parseFloat(fontSizeChooser.getSelectedItem().toString());
          }
        });

    JButton cancel = new JButton("Cancel");
    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            formatText.dispose();
          }
        });

    JPanel buttons = new JPanel();
    buttons.add(ok);
    buttons.add(cancel);
    formatText.getContentPane().add(choosers, BorderLayout.CENTER);
    formatText.getContentPane().add(buttons, BorderLayout.SOUTH);
    formatText.pack();
    formatText.setVisible(true);

    MutableAttributeSet attr = null;
    if (editor != null && accept) {
      attr = new SimpleAttributeSet();
      StyleConstants.setFontFamily(attr, family);
      StyleConstants.setFontSize(attr, (int) fontSize);
      setCharacterAttributes(editor, attr, false);
    }
  }
Example #18
0
  /** Create a font chooser dialog for the specified frame. */
  public FontChooser(Frame owner) {
    super(owner, "Choose a Font"); // Set dialog frame and title

    // This dialog must be used as a modal dialog.  In order to be used
    // as a modeless dialog, it would have to fire a PropertyChangeEvent
    // whenever the selected font changed, so that applications could be
    // notified of the user's selections.
    setModal(true);

    // Figure out what fonts are available on the system
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    fontFamilies = env.getAvailableFontFamilyNames();

    // Set initial values for the properties
    family = fontFamilies[0];
    style = Font.PLAIN;
    size = 18;
    selectedFont = new Font(family, style, size);

    // Create ItemChooser objects that allow the user to select font
    // family, style, and size.
    families = new ItemChooser("Family", fontFamilies, null, 0, ItemChooser.COMBOBOX);
    styles = new ItemChooser("Style", styleNames, styleValues, 0, ItemChooser.COMBOBOX);
    sizes = new ItemChooser("Size", sizeNames, null, 4, ItemChooser.COMBOBOX);

    // Now register event listeners to handle selections
    families.addItemChooserListener(
        new ItemChooser.Listener() {
          public void itemChosen(ItemChooser.Event e) {
            setFontFamily((String) e.getSelectedValue());
          }
        });
    styles.addItemChooserListener(
        new ItemChooser.Listener() {
          public void itemChosen(ItemChooser.Event e) {
            setFontStyle(((Integer) e.getSelectedValue()).intValue());
          }
        });
    sizes.addItemChooserListener(
        new ItemChooser.Listener() {
          public void itemChosen(ItemChooser.Event e) {
            setFontSize(Integer.parseInt((String) e.getSelectedValue()));
          }
        });

    // Create a component to preview the font.
    preview = new JTextArea(defaultPreviewString, 5, 40);
    preview.setFont(selectedFont);

    // Create buttons to dismiss the dialog, and set handlers on them
    okay = new JButton("Okay");
    cancel = new JButton("Cancel");
    okay.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            hide();
          }
        });
    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            selectedFont = null;
            hide();
          }
        });

    // Put the ItemChoosers in a Box
    Box choosersBox = Box.createHorizontalBox();
    choosersBox.add(Box.createHorizontalStrut(15));
    choosersBox.add(families);
    choosersBox.add(Box.createHorizontalStrut(15));
    choosersBox.add(styles);
    choosersBox.add(Box.createHorizontalStrut(15));
    choosersBox.add(sizes);
    choosersBox.add(Box.createHorizontalStrut(15));
    choosersBox.add(Box.createGlue());

    // Put the dismiss buttons in another box
    Box buttonBox = Box.createHorizontalBox();
    buttonBox.add(Box.createGlue());
    buttonBox.add(okay);
    buttonBox.add(Box.createGlue());
    buttonBox.add(cancel);
    buttonBox.add(Box.createGlue());

    // Put the choosers at the top, the buttons at the bottom, and
    // the preview in the middle.
    Container contentPane = getContentPane();
    contentPane.add(new JScrollPane(preview), BorderLayout.CENTER);
    contentPane.add(choosersBox, BorderLayout.NORTH);
    contentPane.add(buttonBox, BorderLayout.SOUTH);

    // Set the dialog size based on the component size.
    pack();
  }
  private JToolBar makeToolBar() {
    JToolBar tool = new JToolBar();
    tool.setFloatable(false);

    // Setup the buttons
    save.setRequestFocusEnabled(false);
    tool.add(save);

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();
    tool.addSeparator();
    cbFonts = new JComboBox(fontNames);
    cbFonts.setRequestFocusEnabled(false);
    cbFonts.setMaximumSize(cbFonts.getPreferredSize());
    cbFonts.setEditable(true);
    ActionListener lst =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (fFamilyChange) {
              fFamilyChange = false;
              return;
            }
            editor.grabFocus();
            setSelectionAttribute(StyleConstants.Family, cbFonts.getSelectedItem().toString());
          }
        };

    cbFonts.addActionListener(lst);
    tool.add(cbFonts);
    tool.addSeparator();
    sSizes = new JSpinner(new SpinnerNumberModel(12, 1, 100, 1));
    sSizes.setRequestFocusEnabled(false);
    sSizes.setMaximumSize(sSizes.getPreferredSize());
    sSizes.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent arg0) {
            if (fSizeChange) {
              fSizeChange = false;
              return;
            }
            setSelectionAttribute(StyleConstants.Size, sSizes.getValue());
            editor.grabFocus();
          }
        });
    tool.add(sSizes);
    tool.addSeparator();

    tbBold = new JToggleButton(LGM.getIconForKey("GameInformationFrame.BOLD")); // $NON-NLS-1$
    tbBold.setRequestFocusEnabled(false);
    lst =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            setSelectionAttribute(StyleConstants.Bold, tbBold.isSelected());
          }
        };
    tbBold.addActionListener(lst);
    tool.add(tbBold);
    tbItalic = new JToggleButton(LGM.getIconForKey("GameInformationFrame.ITALIC")); // $NON-NLS-1$
    tbItalic.setRequestFocusEnabled(false);
    lst =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            setSelectionAttribute(StyleConstants.Italic, tbItalic.isSelected());
          }
        };
    tbItalic.addActionListener(lst);
    tool.add(tbItalic);
    tbUnderline =
        new JToggleButton(LGM.getIconForKey("GameInformationFrame.UNDERLINED")); // $NON-NLS-1$
    tbUnderline.setRequestFocusEnabled(false);
    lst =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            setSelectionAttribute(StyleConstants.Underline, tbUnderline.isSelected());
          }
        };
    tbUnderline.addActionListener(lst);
    tool.add(tbUnderline);

    tool.addSeparator();
    JButton butFontColor =
        new JButton(LGM.getIconForKey("GameInformationFrame.FONTCOLOR")); // $NON-NLS-1$
    butFontColor.setRequestFocusEnabled(false);
    butFontColor.setActionCommand("GameInformationFrame.FONTCOLOR"); // $NON-NLS-1$
    butFontColor.addActionListener(this);
    tool.add(butFontColor);
    JButton but = new JButton(LGM.getIconForKey("GameInformationFrame.COLOR")); // $NON-NLS-1$
    but.setRequestFocusEnabled(false);
    but.setActionCommand("GameInformationFrame.COLOR"); // $NON-NLS-1$
    but.addActionListener(this);
    tool.add(but);
    return tool;
  }
  // Here some legacy code makes use of generics. They are tested, so there
  // is no risk of an actual error, but Java issues a warning.
  @SuppressWarnings("unchecked")
  public DialogParameters(
      JFrame parent, Vector<ParameterDescription> vec, boolean strict, Vector<LayerDesc> layers) {
    super(parent, Globals.messages.getString("Param_opt"), true);

    keyb1 = new OSKeybPanel(KEYBMODES.GREEK);
    keyb2 = new OSKeybPanel(KEYBMODES.MISC);
    keyb1.setField(this);
    keyb2.setField(this);
    keyb.addTab("Greek", keyb1);
    keyb.addTab("Misc", keyb2);
    keyb.setVisible(false);
    v = vec;

    int ycount = 0;

    // We create dynamically all the needed elements.
    // For this reason, we work on arrays of the potentially useful Swing
    // objects.

    jtf = new JTextField[MAX_ELEMENTS];
    jcb = new JCheckBox[MAX_ELEMENTS];
    jco = new JComboBox[MAX_ELEMENTS];

    active = false;
    addComponentListener(this);

    GridBagLayout bgl = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    Container contentPane = getContentPane();
    contentPane.setLayout(bgl);
    boolean extStrict = strict;

    ParameterDescription pd;

    int top = 0;

    JLabel lab;

    tc = 0;
    cc = 0;
    co = 0;

    // We process all parameter passed. Depending on its type, a
    // corresponding interface element will be created.
    // A symmetrical operation is done when validating parameters.

    for (ycount = 0; ycount < v.size(); ++ycount) {
      if (ycount > MAX) break;

      pd = (ParameterDescription) v.elementAt(ycount);

      // We do not need to store label objects, since we do not need
      // to retrieve data from them.

      lab = new JLabel(pd.description);
      constraints.weightx = 100;
      constraints.weighty = 100;
      constraints.gridx = 1;
      constraints.gridy = ycount;
      constraints.gridwidth = 1;
      constraints.gridheight = 1;

      // The first element needs a little bit more space at the top.
      if (ycount == 0) top = 10;
      else top = 0;

      // Here we configure the grid layout

      constraints.insets = new Insets(top, 20, 0, 6);

      constraints.fill = GridBagConstraints.VERTICAL;
      constraints.anchor = GridBagConstraints.EAST;
      lab.setEnabled(!(pd.isExtension && extStrict));

      if (!(pd.parameter instanceof Boolean)) contentPane.add(lab, constraints);

      constraints.anchor = GridBagConstraints.WEST;
      constraints.insets = new Insets(top, 0, 0, 0);
      constraints.fill = GridBagConstraints.HORIZONTAL;

      // Now, depending on the type of parameter we create interface
      // elements and we populate the dialog.

      if (pd.parameter instanceof PointG) {
        jtf[tc] = new JTextField(10);
        jtf[tc].setText("" + ((PointG) (pd.parameter)).x);
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        // Disable FidoCadJ extensions in the strict compatibility mode
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));

        contentPane.add(jtf[tc++], constraints);

        jtf[tc] = new JTextField(10);
        jtf[tc].setText("" + ((PointG) (pd.parameter)).y);
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 3;
        constraints.gridy = ycount;
        constraints.gridwidth = 1;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 6, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jtf[tc++], constraints);
      } else if (pd.parameter instanceof String) {
        jtf[tc] = new JTextField(24);
        jtf[tc].setText((String) (pd.parameter));
        // If we have a String text field in the first position, its
        // contents should be evidenced, since it is supposed to be
        // the most important field (e.g. for the AdvText primitive)
        if (ycount == 0) jtf[tc].selectAll();
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));

        contentPane.add(jtf[tc++], constraints);

      } else if (pd.parameter instanceof Boolean) {
        jcb[cc] = new JCheckBox(pd.description);
        jcb[cc].setSelected(((Boolean) (pd.parameter)).booleanValue());
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jcb[cc].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jcb[cc++], constraints);
      } else if (pd.parameter instanceof Integer) {
        jtf[tc] = new JTextField(24);
        jtf[tc].setText(((Integer) pd.parameter).toString());
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jtf[tc++], constraints);
      } else if (pd.parameter instanceof Float) {
        // TODO.
        // WARNING: (DB) this is supposed to be temporary. In fact, I
        // am planning to upgrade some of the parameters from int
        // to float. But for a few months, the users should not be
        // aware of that, even if the internal representation is
        // slowing being adapted.
        jtf[tc] = new JTextField(24);
        int dummy = java.lang.Math.round((Float) pd.parameter);
        jtf[tc].setText("" + dummy);
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jtf[tc].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jtf[tc++], constraints);
      } else if (pd.parameter instanceof FontG) {
        GraphicsEnvironment gE;
        gE = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] s = gE.getAvailableFontFamilyNames();
        jco[co] = new JComboBox();

        for (int i = 0; i < s.length; ++i) {
          jco[co].addItem(s[i]);
          if (s[i].equals(((FontG) pd.parameter).getFamily())) jco[co].setSelectedIndex(i);
        }
        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jco[co].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jco[co++], constraints);
      } else if (pd.parameter instanceof LayerInfo) {
        jco[co] = new JComboBox(new Vector<LayerDesc>(layers));
        jco[co].setSelectedIndex(((LayerInfo) pd.parameter).layer);
        jco[co].setRenderer(new LayerCellRenderer());

        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jco[co].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jco[co++], constraints);

      } else if (pd.parameter instanceof ArrowInfo) {
        jco[co] = new JComboBox<ArrowInfo>();
        jco[co].addItem(new ArrowInfo(0));
        jco[co].addItem(new ArrowInfo(1));
        jco[co].addItem(new ArrowInfo(2));
        jco[co].addItem(new ArrowInfo(3));

        jco[co].setSelectedIndex(((ArrowInfo) pd.parameter).style);
        jco[co].setRenderer(new ArrowCellRenderer());

        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jco[co].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jco[co++], constraints);

      } else if (pd.parameter instanceof DashInfo) {

        jco[co] = new JComboBox<DashInfo>();

        for (int k = 0; k < Globals.dashNumber; ++k) {
          jco[co].addItem(new DashInfo(k));
        }

        jco[co].setSelectedIndex(((DashInfo) pd.parameter).style);
        jco[co].setRenderer(new DashCellRenderer());

        constraints.weightx = 100;
        constraints.weighty = 100;
        constraints.gridx = 2;
        constraints.gridy = ycount;
        constraints.gridwidth = 2;
        constraints.gridheight = 1;
        constraints.insets = new Insets(top, 0, 0, 20);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        jco[co].setEnabled(!(pd.isExtension && extStrict));
        contentPane.add(jco[co++], constraints);
      }
    }
    // Put the OK and Cancel buttons and make them active.
    JButton ok = new JButton(Globals.messages.getString("Ok_btn"));
    JButton cancel = new JButton(Globals.messages.getString("Cancel_btn"));
    JButton keybd = new JButton("\u00B6\u2211\u221A"); // phylum
    keybd.setFocusable(false);
    keybd.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // If at this point, the keyboard is not visible, this means
            // that it will become visible in a while. It is better to
            // resize first and then show up the keyboard.
            if (keyb.isVisible()) {
              MIN_WIDTH = 400;
              MIN_HEIGHT = 350;
            } else {
              MIN_WIDTH = 400;
              MIN_HEIGHT = 500;
            }
            // setSize(MIN_WIDTH, MIN_HEIGHT);
            keyb.setVisible(!keyb.isVisible());
            pack();
          }
        });

    constraints.gridx = 0;
    constraints.gridy = ycount++;
    constraints.gridwidth = 4;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(6, 20, 20, 20);

    // Put the OK and Cancel buttons and make them active.
    Box b = Box.createHorizontalBox();
    b.add(keybd); // phylum

    b.add(Box.createHorizontalGlue());
    ok.setPreferredSize(cancel.getPreferredSize());

    if (Globals.okCancelWinOrder) {
      b.add(ok);
      b.add(Box.createHorizontalStrut(12));
      b.add(cancel);

    } else {
      b.add(cancel);
      b.add(Box.createHorizontalStrut(12));
      b.add(ok);
    }
    // b.add(Box.createHorizontalStrut(12));
    contentPane.add(b, constraints);

    constraints.gridx = 0;
    constraints.gridy = ycount;
    constraints.gridwidth = 4;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.EAST;
    constraints.insets = new Insets(6, 20, 20, 20);

    contentPane.add(keyb, constraints);

    ok.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            try {
              int ycount;
              ParameterDescription pd;
              tc = 0;
              cc = 0;
              co = 0;

              // Here we read all the contents of the interface and we
              // update the contents of the parameter description array.

              for (ycount = 0; ycount < v.size(); ++ycount) {
                if (ycount > MAX) break;
                pd = (ParameterDescription) v.elementAt(ycount);

                if (pd.parameter instanceof PointG) {
                  ((PointG) (pd.parameter)).x = Integer.parseInt(jtf[tc++].getText());
                  ((PointG) (pd.parameter)).y = Integer.parseInt(jtf[tc++].getText());
                } else if (pd.parameter instanceof String) {
                  pd.parameter = jtf[tc++].getText();
                } else if (pd.parameter instanceof Boolean) {
                  pd.parameter = Boolean.valueOf(jcb[cc++].isSelected());
                } else if (pd.parameter instanceof Integer) {
                  pd.parameter = Integer.valueOf(Integer.parseInt(jtf[tc++].getText()));
                } else if (pd.parameter instanceof Float) {
                  pd.parameter = Float.valueOf(Float.parseFloat(jtf[tc++].getText()));
                } else if (pd.parameter instanceof FontG) {
                  pd.parameter = new FontG((String) jco[co++].getSelectedItem());
                } else if (pd.parameter instanceof LayerInfo) {
                  pd.parameter = new LayerInfo(jco[co++].getSelectedIndex());
                } else if (pd.parameter instanceof ArrowInfo) {
                  pd.parameter = new ArrowInfo(jco[co++].getSelectedIndex());
                } else if (pd.parameter instanceof DashInfo) {
                  pd.parameter = new DashInfo(jco[co++].getSelectedIndex());
                }
              }
            } catch (NumberFormatException E) {
              // Error detected. Probably, the user has entered an
              // invalid string when FidoCadJ was expecting a numerical
              // input.

              JOptionPane.showMessageDialog(
                  null,
                  Globals.messages.getString("Format_invalid"),
                  "",
                  JOptionPane.INFORMATION_MESSAGE);
              return;
            }

            active = true;
            // Globals.activeWindow.setEnabled(true);
            setVisible(false);
            keyb.setVisible(false);
          }
        });
    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            // Globals.activeWindow.setEnabled(true);
            setVisible(false);
            keyb.setVisible(false);
          }
        });
    // Here is an action in which the dialog is closed

    AbstractAction cancelAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            // Globals.activeWindow.setEnabled(true);
            setVisible(false);
            keyb.setVisible(false);
          }
        };
    DialogUtil.addCancelEscape(this, cancelAction);

    this.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            // Globals.activeWindow.setEnabled(true);
            keyb.setVisible(false);
          }
        });

    pack();
    DialogUtil.center(this);
    getRootPane().setDefaultButton(ok);
  }
Example #21
0
  public MUIFactory() {
    size = new DefaultComboBoxModel(MUIFactory.FONT_SIZES);
    styles = new DefaultComboBoxModel();
    final ModeController modeController = Controller.getCurrentModeController();
    final MNodeStyleController styleController =
        (MNodeStyleController) modeController.getExtension(NodeStyleController.class);
    final GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final String[] envFonts = gEnv.getAvailableFontFamilyNames();
    fonts = new DefaultComboBoxModel(envFonts);
    final ListDataListener fontsListener =
        new ListDataListener() {
          public void intervalRemoved(final ListDataEvent e) {}

          public void intervalAdded(final ListDataEvent e) {}

          public void contentsChanged(final ListDataEvent e) {
            if (e.getIndex0() != -1) {
              return;
            }
            if (ignoreChangeEvent) {
              return;
            }
            ignoreChangeEvent = true;
            final DefaultComboBoxModel source = (DefaultComboBoxModel) e.getSource();
            styleController.setFontFamily((String) source.getSelectedItem());
            ignoreChangeEvent = false;
          }
        };
    fonts.addListDataListener(fontsListener);
    final ListDataListener sizeListener =
        new ListDataListener() {
          public void intervalRemoved(final ListDataEvent e) {}

          public void intervalAdded(final ListDataEvent e) {}

          public void contentsChanged(final ListDataEvent e) {
            if (e.getIndex0() != -1) {
              return;
            }
            if (ignoreChangeEvent) {
              return;
            }
            try {
              final DefaultComboBoxModel source = (DefaultComboBoxModel) e.getSource();
              final int intSize = Integer.parseInt(((String) source.getSelectedItem()));
              styleController.setFontSize(intSize);
            } catch (final NumberFormatException nfe) {
            }
          }
        };
    size.addListDataListener(sizeListener);
    final ListDataListener styleListener =
        new ListDataListener() {
          public void intervalRemoved(final ListDataEvent e) {}

          public void intervalAdded(final ListDataEvent e) {}

          public void contentsChanged(final ListDataEvent e) {
            if (e.getIndex0() != -1) {
              return;
            }
            if (ignoreChangeEvent) {
              return;
            }
            final DefaultComboBoxModel source = (DefaultComboBoxModel) e.getSource();
            final IStyle style = (IStyle) source.getSelectedItem();
            final MLogicalStyleController controller =
                (MLogicalStyleController) modeController.getExtension(LogicalStyleController.class);
            controller.setStyle(style);
          }
        };
    styles.addListDataListener(styleListener);
  }