Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/virtuosotechnologies/lib/basiccommand/builder/ToolBarToggleItemBuilderNode.java


1   /*
2   ================================================================================
3   
4     FILE:  ToolBarToggleItemBuilderNode.java
5     
6     PROJECT:
7     
8       Virtuoso Utilities
9     
10    CONTENTS:
11    
12      A builder that creates a special toggle toolbar item that isn't a true
13      ToggleButton but instead changes its icon and/or name.
14    
15    PROGRAMMERS:
16    
17      Daniel Azuma (DA)  <dazuma@kagi.com>
18    
19    COPYRIGHT:
20    
21      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
22      
23      This program is free software; you can redistribute it and/or
24      modify it under the terms of the GNU General Public License as
25      published by the Free Software Foundation; either version 2
26      of the License, or (at your option) any later version.
27      
28      This program is distributed in the hope that it will be useful,
29      but WITHOUT ANY WARRANTY; without even the implied warranty of
30      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31      GNU General Public License for more details.
32      
33      You should have received a copy of the GNU General Public
34      License along with this program; if not, write to
35        Free Software Foundation, Inc.
36        59 Temple Place, Suite 330
37        Boston, MA 02111-1307 USA
38  
39  ================================================================================
40  */
41  
42  
43  package com.virtuosotechnologies.lib.basiccommand.builder;
44  
45  
46  import javax.swing.JButton;
47  import java.awt.Insets;
48  import java.awt.event.ActionListener;
49  import java.awt.event.ActionEvent;
50  
51  import com.virtuosotechnologies.lib.command.CommandNode;
52  import com.virtuosotechnologies.lib.basiccommand.BasicCommandNode;
53  
54  
55  /**
56   * A builder that creates a special toggle toolbar item that isn't a true
57   * ToggleButton but instead changes its icon and/or name.
58   */
59  public class ToolBarToggleItemBuilderNode
60  extends AbstractSwingButtonBuilderNode
61  implements
62    ActionListener
63  {
64    /**
65     * Constructor
66     */
67    protected ToolBarToggleItemBuilderNode(
68      CommandNode commandNode,
69      AbstractBranchBuilderNode parent,
70      int index)
71    {
72      super(commandNode, parent, index);
73    }
74    
75    
76    /**
77     * Override this method to create the initial element object.
78     */
79    protected Object createInitialElement()
80    {
81      JButton button = new JButton();
82      button.setMargin(new Insets(0, 0, 0, 0));
83      button.addActionListener(this);
84      return button;
85    }
86    
87    
88    /**
89     * Action listener that changes the state.
90     */
91    public void actionPerformed(
92      ActionEvent ev)
93    {
94      CommandNode node = getCommandNode();
95      boolean oldValue = Boolean.TRUE.equals(node.getValue(
96        BasicCommandNode.SELECTION_STATE_PROPERTY));
97      if (getParent().getCommandNode().getFlavor().equalsOrExtends(
98        BasicCommandNode.RADIOMUTEX_FLAVOR))
99      {
100       if (!oldValue)
101       {
102         node.putValue(BasicCommandNode.SELECTION_STATE_PROPERTY, Boolean.TRUE);
103       }
104     }
105     else
106     {
107       node.putValue(BasicCommandNode.SELECTION_STATE_PROPERTY,
108         oldValue ? Boolean.FALSE : Boolean.TRUE);
109     }
110   }
111 }