1 23 24 package org.objectweb.fractal.gui.menu.control; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.graph.model.Display; 29 import org.objectweb.fractal.gui.model.Component; 30 import org.objectweb.fractal.gui.model.Configuration; 31 import org.objectweb.fractal.gui.graph.view.Printer; 32 import org.objectweb.fractal.gui.selection.model.Selection; 33 import org.objectweb.fractal.swing.AbstractAction; 34 35 import java.awt.event.ActionEvent ; 36 import java.net.URL ; 37 import java.util.List ; 38 39 import javax.swing.ImageIcon ; 40 import javax.swing.JOptionPane ; 41 import javax.swing.KeyStroke ; 42 43 46 47 public class PrintAction extends AbstractAction implements 48 BindingController 49 { 50 51 public final static String CONFIGURATION_BINDING = "configuration"; 52 53 public final static String SELECTION_BINDING = "selection"; 54 55 public final static String DISPLAY_BINDING = "display"; 56 57 public final static String PRINTER_BINDING = "printer"; 58 59 private Configuration configuration; 60 61 private Selection selection; 62 63 private Display display; 64 65 private Printer printer; 66 67 70 71 public PrintAction () { 72 putValue(NAME, "Print"); 73 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control P")); 74 putValue(SHORT_DESCRIPTION, "Print"); 75 URL url = getClass().getResource( 76 "/org/objectweb/fractal/gui/resources/print.gif"); 77 putValue(SMALL_ICON, new ImageIcon (url)); 78 setEnabled(true); 79 } 80 81 85 public String [] listFc () { 86 return new String [] { 87 CONFIGURATION_BINDING, 88 SELECTION_BINDING, 89 DISPLAY_BINDING, 90 PRINTER_BINDING 91 }; 92 } 93 94 public Object lookupFc (final String clientItfName) { 95 if (CONFIGURATION_BINDING.equals(clientItfName)) { 96 return configuration; 97 } else if (SELECTION_BINDING.equals(clientItfName)) { 98 return selection; 99 } else if (DISPLAY_BINDING.equals(clientItfName)) { 100 return display; 101 } else if (PRINTER_BINDING.equals(clientItfName)) { 102 return printer; 103 } 104 return null; 105 } 106 107 public void bindFc ( 108 final String clientItfName, 109 final Object serverItf) 110 { 111 if (CONFIGURATION_BINDING.equals(clientItfName)) { 112 configuration = (Configuration)serverItf; 113 } else if (SELECTION_BINDING.equals(clientItfName)) { 114 selection = (Selection)serverItf; 115 } else if (DISPLAY_BINDING.equals(clientItfName)) { 116 display = (Display)serverItf; 117 } else if (PRINTER_BINDING.equals(clientItfName)) { 118 printer = (Printer)serverItf; 119 } 120 } 121 122 public void unbindFc (final String clientItfName) { 123 if (CONFIGURATION_BINDING.equals(clientItfName)) { 124 configuration = null; 125 } else if (SELECTION_BINDING.equals(clientItfName)) { 126 selection = null; 127 } else if (DISPLAY_BINDING.equals(clientItfName)) { 128 display = null; 129 } else if (PRINTER_BINDING.equals(clientItfName)) { 130 printer = null; 131 } 132 } 133 134 138 public void actionPerformed (final ActionEvent e) { 139 Object o = selection.getSelection(); 140 if (o instanceof Component) { 141 Component c = (Component)o; 142 printer.setType(Printer.TYPE_PRINT); 143 144 List subComponents = c.getSubComponents(); 145 if (subComponents.size() > 0) { 146 Object [] options = {"Yes", "No" }; 147 int n = JOptionPane.showOptionDialog( 148 null, 149 "Do you want to print all components of the current configuration ?", 150 "Warning", 151 JOptionPane.YES_NO_CANCEL_OPTION, 152 JOptionPane.QUESTION_MESSAGE, 153 null, 154 options, 155 options[0]); 156 if (n == 0) { 157 imprime (c.getRootComponent(), 0); 158 configuration.setRootComponent(c.getRootComponent()); 159 selection.selectComponent(c.getRootComponent()); 160 } 161 else printer.print(true, c); 162 } 163 } 164 } 165 166 private void imprime (final Component c, final int lvl) { 167 168 boolean on_continue = true; 169 if (lvl == 0) on_continue = printer.print(true, c); 170 else on_continue = printer.print(false, c); 171 if (!on_continue) return; 172 173 List subComponents = c.getSubComponents(); 174 for (int i = 0; i < subComponents.size(); ++i) { 175 Component subC = (Component)subComponents.get(i); 176 imprime (subC, lvl+1); 177 } 178 } 179 } 180 | Popular Tags |