Results 1 to 7 of 7
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default strange persisting error

    Sorry for me being so persisting, I have to say once again that the following error I find
    concerning and I do not understand what causes it.
    I have changed the name of changeSupport at line 51 into changeSupport2
    All following changeSupport are marked as errors, of course!
    Except one at line 152.
    This changeSupport seems to be ok and I do not know why and what
    sets that variable!


    Java Code:
    package willemwriter;
    
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.beans.PropertyChangeListener;
    import java.beans.PropertyChangeSupport;
    import java.util.ArrayList;
    import javax.swing.*;
    import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
    
    import willemwriter.MenuFontMenu2.ColorAction;
    import willemwriter.MenuFontMenu2.SizeAction;
    import willemwriter.MenuFontMenu2.StyleAction;
    
    
    /**
     *
     * @author willem
     */
     class MenuFontMenu  {
    
         private MenuFontMenu2 fontMenu2;
         private Container textcanvas;
         private Font font;
         private IconImport iconImport;
         
         private JRadioButtonMenuItem rbShortList, rbSetup, rbAllfonts;
         private JRadioButtonMenuItem[] radiobAll, radiobShortlist;
         private JCheckBoxMenuItem[] checkbMenuList;
         private ButtonGroup shortlistgroup;
    
         private String currentFont;
         private int currentStyle, currentSize;
         private Color currentColor;
    
         private JMenu fontMenu, allFontMenu, selectFontMenu, shortFontMenu;
         private JMenuItem dummyItem;
    
         private String[] allFontNameList; //fontSizeList;
         private ArrayList shortFontNameList;
    
         private StyleAction[] styleActions;
         private SizeAction[] sizeActions;
         private ColorAction[] colorActions;
    
         private MenuActionListener menulistener;
         private AbstractAction shortListFontsAction;
         private PropertyChangeSupport changeSupport2;
         private MenuFontMenu2.CurrentFontInfo currentFontInfo;
    
    
    
    
         public MenuFontMenu(Container textcanvas) {
    
             // the text component reference
             this.textcanvas = textcanvas;
    
             changeSupport = new PropertyChangeSupport(this);
    
             // Icon iamge import
             iconImport = new IconImport("http://www.java-forums.org/images/");
    
             // Get the system fonts
             Fontclass fontclass = new Fontclass();
             allFontNameList = fontclass.getAllFontNames();
    
             shortlistgroup = new ButtonGroup();
    
             menulistener = new MenuActionListener();
             shortFontNameList = new ArrayList();
        
             //font menu extention for setting style, size and color
             fontMenu2 = new MenuFontMenu2(textcanvas, changeSupport);
    
        //   StayOpenCheckBoxMenuItemUI stayopen = new StayOpenCheckBoxMenuItemUI();
    
         }
    
        
         public ColorAction[] getColorAction()  { 
             return fontMenu2.getColorAction();
         }
    
          public StyleAction[] getStyleAction() { 
             return fontMenu2.getStyleAction();
         }
    
         public SizeAction[] getSizeAction() {
             return fontMenu2.getSizeAction();
         }
    
         public ArrayList getShortFontNameList()  {
             return shortFontNameList;
         }
        
    
    
         /**
         * Create the Font menu to support family, style, size and color
         * The family, style size and color elements are declared in
         * the Fontclass.
         * The buildFontMenu returns a populated menu: fontMenu
         * The variable currentFont contains the selected font family
         * The single font menu list gets removed and installed constantly
         * 1) for selection radio buttons 2) for setting up the short list
         * check boxes. The font family list is at the 4th position
         * of the font menu.
         * The second class MenuFontMenu2 adds the style size and color to
         * the menu (down part from postion 4)
         */
    
         public JMenu buildFontMenu() {
            // The actions of the three radio buttons: all/short list/make selection
            // Action for Font menu items / the all font list
            AbstractAction allFontsAction = new AbstractAction() {
                {	// "Constructor"
                    putValue(NAME, "All Fonts");
                    putValue(SMALL_ICON, iconImport.getImageIcon("whatever"));
                    putValue(MNEMONIC_KEY, new Integer('N'));
                    putValue(SHORT_DESCRIPTION, "Creates a whatever");
                    putValue(LONG_DESCRIPTION, "Creating new whatever...");
                }
                public void actionPerformed(ActionEvent evt) {
                    fontMenu.remove(4);
                    fontMenu.insert(allFontMenu, 4);
                    //remember the previus selection
                    for (int i= 0; i < allFontNameList.length; i++) {
                        radiobAll[i].setSelected(false); 
                        if (allFontNameList[i].equals(currentFont)) {
                            radiobAll[i].setSelected(true);
                        }
                    }
                }
            };
            // the short font list after construction (see next block)
            shortListFontsAction = new AbstractAction() {
                {
                    putValue(NAME, "Short Fontlist");
                    putValue(SMALL_ICON, iconImport.getImageIcon("whatever"));
                    putValue(MNEMONIC_KEY, new Integer('N'));
                    putValue(SHORT_DESCRIPTION, "Creates whatever");
                    putValue(LONG_DESCRIPTION, "Creating whatever...");
                }
                public void actionPerformed(ActionEvent evt) {
                    fontMenu.remove(4);
                    fontMenu.insert(shortFontMenu, 4);
    
                    changeSupport.firePropertyChange("SHORTLIST",false,true);
    
                    // removing the dummy of the
                    if (shortFontMenu.getItemCount() != 0 &
                                            !shortFontMenu.equals(dummyItem))  {
                        shortFontMenu.remove(dummyItem);
                    } else {
                        shortFontMenu.add(dummyItem);
                    }
                    
                    //remember the previous selection
                    if (shortFontMenu.getItemCount() > 0 & currentFont != null)  {
                        shortlistgroup.clearSelection();
                        
                       int i = shortFontNameList.indexOf(currentFont);
                       if (i >= 0) {
                            JRadioButtonMenuItem rb =
                              (JRadioButtonMenuItem) shortFontMenu.getItem(i);
                            if (rb != null)
                            rb.setSelected(true);
                       }
                    }
                }
            };
            // constructing the short list see also makeShortFontlist
            // and MenuActionListener. the list is stored in shortMenuMap
            // and shortFontMenu
            AbstractAction setupshortListFontsAction = new AbstractAction() {
                {
                    putValue(NAME, "Setup Shortlist");
                    putValue(SMALL_ICON, iconImport.getImageIcon("whatever"));
                    putValue(MNEMONIC_KEY, new Integer('N'));
                    putValue(SHORT_DESCRIPTION, "Creates a new whatever");
                    putValue(LONG_DESCRIPTION, "Creating new whatever...");
                }
                public void actionPerformed(ActionEvent evt) {
                    fontMenu.remove(4);
                    // the selection was constructed at MenuActionListener
                    fontMenu.insert(selectFontMenu, 4);
                
                }
            };
    
            // the several menus
            fontMenu = new JMenu("Fonts");
            ButtonGroup group = new ButtonGroup();
    
            // first the three fixed radio buttons All/ Short list/
            //selecting short list
            rbAllfonts = new JRadioButtonMenuItem(allFontsAction);
            rbAllfonts.setSelected(true);
            fontMenu.add(rbAllfonts);
            group.add(rbAllfonts);
    
            rbShortList = new JRadioButtonMenuItem(shortListFontsAction);
            rbShortList.setSelected(false);
            rbShortList.setEnabled(true);
            fontMenu.add(rbShortList);
            group.add(rbShortList);
    
            rbSetup = new JRadioButtonMenuItem(setupshortListFontsAction);
            rbSetup.setSelected(false);
            fontMenu.add(rbSetup);
            group.add(rbSetup);
            fontMenu.addSeparator();
    
            // a second menu added to show the font listings All/Short
            allFontMenu = new JMenu("Font List");
            selectFontMenu = new JMenu("Font List");
            shortFontMenu = new JMenu("Font List");
    
            buildFontMenuItems(allFontNameList);
            dummyItem = new  JMenuItem("EMPTY");
            dummyItem.setEnabled(false);
    
            // add all system fonts to the menu
            fontMenu.add(allFontMenu);
    
            MenuScroller.setScrollerFor(allFontMenu);
            MenuScroller.setScrollerFor(selectFontMenu);
    
            // the menu  extion from the class MenuFontMenu2
            fontMenu.addSeparator();// the addional font menus of style, size and
            fontMenu.add(fontMenu2.buildFontMenu2(fontMenu)); // color
    
           
            return fontMenu; // returns the populated menu
         }
    
        
         // create the fourth menu the all font menu or select short list menu
         // building all radio buttons and checkboxes for selection (done only once)
         public void buildFontMenuItems(String[] names)  {// font name
              radiobAll = new JRadioButtonMenuItem[names.length];
              radiobShortlist = new JRadioButtonMenuItem[names.length];
              checkbMenuList = new JCheckBoxMenuItem[names.length];
              ButtonGroup allFontgroup = new ButtonGroup();
              Font ft = fontMenu.getFont();
              //the names-array contains all font families see FontClass
              for (int i = 0; i < names.length; i++) {
                    font = new Font(names[i], Font.PLAIN, 16);
                    radiobAll[i] = new JRadioButtonMenuItem(names[i]);
                    checkbMenuList[i] = new JCheckBoxMenuItem(names[i]);
    
                    radiobAll[i].setActionCommand(names[i]);
                    checkbMenuList[i].setActionCommand(names[i]);
    
                    radiobAll[i].setFont(font);
                    checkbMenuList[i].setFont(font);
    
                    allFontgroup.add(radiobAll[i]);
    
                    radiobAll[i].addActionListener(menulistener);
                    checkbMenuList[i].addActionListener(menulistener);
    
                    selectFontMenu.add(checkbMenuList[i]);
                    allFontMenu.add(radiobAll[i]);
              }
              allFontMenu.setFont(ft);
              selectFontMenu.setFont(ft);
         }
    
         
         // this method gets called when selecting the font families for the
         // short font menu list stored in: shortMenuMap and shortFontMenu
         // this menu gets removed and installed at the 4th position of the font menu
         public void makeShortFontlist(ActionEvent evt)  {
            String cmd = evt.getActionCommand();
            JRadioButtonMenuItem rb;
            Font ft = fontMenu.getFont();
            for (int i = 0; i < allFontNameList.length; i++) {
                String select = checkbMenuList[i].getActionCommand();
                if  (cmd.equals(select)) {
                    if (checkbMenuList[i].isSelected()) {   // adding onto the list
                        font = new Font(select, Font.PLAIN, 16); // when selected
                        rb = new JRadioButtonMenuItem(select);
                        rb.setActionCommand(select);
                        rb.addActionListener(menulistener);
                        rb.setFont(font);
                        shortlistgroup.add(rb);
                        shortFontMenu.add(rb);
                        shortFontNameList.add(select);
    
                    } else { // removing from the list
                        int i2 = shortFontNameList.indexOf(select);
                        if (i2 >= 0) {
                            System.out.println("remove " + select);
                            rb = (JRadioButtonMenuItem) shortFontMenu.getItem(i2);
                            shortFontNameList.remove(select);
                            shortlistgroup.remove(rb);
                            shortFontMenu.remove(rb);
                        }
                    }
                }
            }
         }
    
          class MenuActionListener implements ActionListener{
            public void actionPerformed(ActionEvent evt) {
             
                // here setup the font short list which appears on the menu and
                // and the second tool bar
                 
                if (rbSetup.isSelected()){          
                    makeShortFontlist(evt);
                } else { // here: readout the font family selection
                    if (evt.getSource().getClass().getName().equals(
                                            "javax.swing.JComboBox"))  {
                        JComboBox source = (JComboBox) evt.getSource();
                        if (source.getName() != null)
                        currentFont = source.getName();
                    } else {
                        currentFont = evt.getActionCommand();
                    }
                    changeSupport.firePropertyChange("FONTCHANGE",false,true);
                        System.out.println("current font FAMILY: "
                                                + currentFont);
                } 
            }
         }
    
        public void addPropertyChangeListener(String property,
                                                    PropertyChangeListener p) {
            changeSupport.addPropertyChangeListener(property, p);
        }
    
        public void removePropertyChangeListener(String property,
                                                    PropertyChangeListener p) {
            changeSupport.removePropertyChangeListener(p);
        }
    
        class StayOpenCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
            @Override
            protected void doClick(MenuSelectionManager msm) {
                menuItem.doClick(0);
    
            }
        }
    
    
    }

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: strange persisting error

    At the AbstractAction

    Field Summary

    Fields
    Modifier and Type Field and Description
    protected SwingPropertyChangeSupport changeSupport
    If any PropertyChangeListeners have been registered, the changeSupport field describes them.
    protected boolean enabled
    Specifies whether action is enabled; the default is true.

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: strange persisting error

    Might this be the cause: AbstractAction (Java Platform SE 7 )

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,916
    Rep Power
    5

    Default Re: strange persisting error

    Yep! When you create an anonymous class you inherit the public and protected fields. And changeSupport is declared protected (check out the field summary in the Javadoc for AbstractAction). I have my syntax colors setup to specially highlight inherited fields when they are being used. I suggest you do the same if possible.

    Regards,
    Jim
    Last edited by jim829; 02-02-2014 at 09:12 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: strange persisting error

    I do not know how to set colors in Netbeans of variables,
    but the idea is great and I will look into it, thanks!
    ps this AbstractAction field made me "loose" two hours!

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,916
    Rep Power
    5

    Default Re: strange persisting error

    I don't use it but I happen to have it installed. So it was pretty straight forward. Tools-->Options-->Fonts and Colors.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

Similar Threads

  1. Strange Error
    By Zelaine in forum New To Java
    Replies: 11
    Last Post: 09-18-2013, 09:21 PM
  2. Strange Error
    By willemien in forum AWT / Swing
    Replies: 24
    Last Post: 04-19-2013, 08:26 PM
  3. strange error in eclipse
    By stevenpalomino in forum New To Java
    Replies: 29
    Last Post: 06-25-2011, 02:46 PM
  4. Strange Error
    By AJArmstron@aol.com in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 10:31 PM
  5. strange Error message
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 12:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •