001: /*
002: * Copyright (c) 2005-2008 Flamingo / Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Flamingo Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package test.ribbon;
031:
032: import java.awt.*;
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035: import java.awt.image.BufferedImage;
036:
037: import javax.swing.*;
038:
039: import org.jvnet.flamingo.common.JCommandButton;
040: import org.jvnet.flamingo.common.icon.ResizableIcon;
041: import org.jvnet.flamingo.ribbon.*;
042: import org.jvnet.flamingo.svg.SvgBatikResizableIcon;
043:
044: public class SimpleRibbon extends JFrame {
045: private JPopupMenu popupMenu = new JPopupMenu();
046:
047: private AbstractButton getIconButton(Icon icon, boolean isToggle,
048: boolean isSelected, boolean hasPopup) {
049: AbstractButton button = isToggle ? new JToggleButton(icon)
050: : new JButton(icon);
051: if (isSelected)
052: button.setSelected(true);
053: button.setPreferredSize(new Dimension(icon.getIconWidth(), icon
054: .getIconHeight()));
055: button.setMargin(new Insets(2, 2, 2, 2));
056: return button;
057: }
058:
059: private JRibbonBand getClipboardBand() {
060: JRibbonBand clipboardBand = new JRibbonBand("Clipboard",
061: SvgBatikResizableIcon.getSvgIcon(BasicCheckRibbon.class
062: .getClassLoader().getResource(
063: "test/svg/edit-paste.svg"),
064: new Dimension(32, 32)), null);
065:
066: ResizableIcon icon = SvgBatikResizableIcon.getSvgIcon(
067: BasicCheckRibbon.class.getClassLoader().getResource(
068: "test/svg/edit-paste.svg"), new Dimension(32,
069: 32));
070: JCommandButton pasteButton = new JCommandButton("Paste", icon);
071: clipboardBand.addGalleryButton(pasteButton,
072: RibbonElementPriority.LOW);
073:
074: return clipboardBand;
075: }
076:
077: protected JRibbon ribbon;
078:
079: public SimpleRibbon() {
080: super ("Ribbon test");
081: this .setIconImage(new BufferedImage(1, 1,
082: BufferedImage.TYPE_INT_ARGB));
083:
084: this .setLayout(new BorderLayout());
085: this .ribbon = new JRibbon();
086: ribbon.add(new JLabel("File"));
087: ribbon.add(new JSeparator(JSeparator.VERTICAL));
088:
089: this .add(ribbon, BorderLayout.NORTH);
090:
091: this .popupMenu = new JPopupMenu();
092: this .popupMenu.add(new JMenuItem("Test menu item 1"));
093: this .popupMenu.add(new JMenuItem("Test menu item 2"));
094: this .popupMenu.addSeparator();
095: this .popupMenu.add(new JMenuItem("Test menu item 3"));
096: this .popupMenu.add(new JMenuItem("Test menu item 4"));
097: this .popupMenu.add(new JMenuItem("Test menu item 5"));
098: }
099:
100: public void configureRibbon() {
101: RibbonTask writeTask = new RibbonTask();
102: JRibbonBand clipboardBand = this .getClipboardBand();
103: writeTask.addBand(clipboardBand);
104:
105: ribbon.addTask("Write", writeTask);
106:
107: JPanel controlPanel = new JPanel(new FlowLayout(
108: FlowLayout.CENTER));
109: this .configureControlPanel(controlPanel);
110:
111: this .add(controlPanel, BorderLayout.SOUTH);
112: }
113:
114: protected void configureControlPanel(JPanel controlPanel) {
115: JButton bl = new JButton("Align left");
116: bl.addActionListener(new ActionListener() {
117: public void actionPerformed(ActionEvent e) {
118: ribbon.setAlignment(SwingConstants.LEFT);
119: }
120: });
121: controlPanel.add(bl);
122: JButton bc = new JButton("Align center");
123: bc.addActionListener(new ActionListener() {
124: public void actionPerformed(ActionEvent e) {
125: ribbon.setAlignment(SwingConstants.CENTER);
126: }
127: });
128: controlPanel.add(bc);
129: JButton br = new JButton("Align right");
130: br.addActionListener(new ActionListener() {
131: public void actionPerformed(ActionEvent e) {
132: ribbon.setAlignment(SwingConstants.RIGHT);
133: }
134: });
135: controlPanel.add(br);
136: }
137:
138: public static void main(String[] args) {
139: try {
140: UIManager
141: .setLookAndFeel("org.jvnet.substance.SubstanceLookAndFeel");
142: } catch (Exception e) {
143: e.printStackTrace();
144: }
145: RepaintManager.setCurrentManager(new TracingRepaintManager());
146: JFrame.setDefaultLookAndFeelDecorated(true);
147: SwingUtilities.invokeLater(new Runnable() {
148: public void run() {
149: SimpleRibbon c = new SimpleRibbon();
150: c.configureRibbon();
151: Rectangle r = GraphicsEnvironment
152: .getLocalGraphicsEnvironment()
153: .getMaximumWindowBounds();
154: c
155: .setPreferredSize(new Dimension(r.width,
156: r.height / 2));
157: c.pack();
158: c.setLocation(r.x, r.y);
159: c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
160: c.setVisible(true);
161: }
162: });
163: }
164: }
|