/** Save the current project. If no project is selcted, will ask for filename for new poroject. */ protected void saveProject() { if (controlcenter.hasProject()) { controlcenter.saveProject(); } else { saveProjectAs(); } }
/** Open a project. Asks the user for a project file name. */ protected void openProject() { if (filechooser.showDialog(this, "Open Project") == JFileChooser.APPROVE_OPTION) { final File file = filechooser.getSelectedFile(); SServiceProvider.getService(controlcenter.getServiceProvider(), ILibraryService.class) .addResultListener( new SwingDefaultResultListener(ControlCenterWindow.this) { public void customResultAvailable(Object source, Object result) { ClassLoader cl = ((ILibraryService) result).getClassLoader(); boolean canopen = file != null && file.canWrite() && file.getName() .toLowerCase() .endsWith(ControlCenter.JCCPROJECT_EXTENSION); if (canopen) { controlcenter.saveProject(); controlcenter.closeProject(); try { controlcenter.openProject(file, cl); // , true); } catch (Exception e) { canopen = false; } } if (!canopen) { SwingUtilities.invokeLater( new Runnable() { public void run() { String msg = SUtil.wrapText("Cannot open the project from file:\n" + file); JOptionPane.showMessageDialog( ControlCenterWindow.this, msg, "Cannot open the project", JOptionPane.ERROR_MESSAGE); } }); } } }); } }
public void actionPerformed(ActionEvent e) { controlcenter.saveProject(); controlcenter.closeProject(); }
public void actionPerformed(ActionEvent e) { controlcenter.exit(); }
/** * Create a toolbar containing the given tools (if any). * * @param template Conta */ protected void changeToolBar(JComponent[] template, IControlCenterPlugin selplugin) { // Setup the tool bar. if (toolbar == null) { toolbar = new JToolBar("Main Toolbar"); getContentPane().add(BorderLayout.NORTH, toolbar); // Add standard entries (after gap). toolbar.add(Box.createGlue()); toolcnt++; toolbar.addSeparator(); toolcnt++; // ButtonGroup bg = new ButtonGroup(); IControlCenterPlugin[] plugins = controlcenter.getPlugins(); for (int i = 0; i < plugins.length; i++) { final IControlCenterPlugin plugin = plugins[i]; // final JToggleButton button = new JToggleButton(new PluginAction(plugins[i])); final JButton button = new JButton(new PluginAction(plugins[i])); Icon ic = plugin.getToolIcon(selplugin.getName().equals(plugins[i].getName())); if (ic != null) button.setIcon(ic); else button.setText(plugins[i].getName()); button.setText("A"); button.putClientProperty("plugin", plugins[i]); button.setBorder(null); button.setText(null); button.setMinimumSize(BUTTON_DIM); button.setHorizontalAlignment(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); button.setToolTipText(plugins[i].getName()); button .getModel() .addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { // System.out.println(plugin.getName()+" :"+button.isSelected()); button.setIcon(plugin.getToolIcon(button.isSelected())); } }); // if(plugins[i].getHelpID()!=null) // SHelp.setupHelp(button, plugins[i].getHelpID()); // bg.add(button); toolbar.add(button); toolcnt++; } toolbar.addSeparator(); toolcnt++; toolbar.add(new JadexLogoButton(toolbar)); toolcnt++; } else { while (toolbar.getComponentCount() > toolcnt) { // Component comp = toolbar.getComponent(0); toolbar.remove(0); // if(lasttoolbar!=null) // lasttoolbar.add(comp); } } for (int i = 0; template != null && i < template.length; i++) toolbar.add(template[i], i); // lasttoolbar = template; // Select plugins for (int i = 0; i < toolbar.getComponentCount(); i++) { JComponent comp = (JComponent) toolbar.getComponent(i); if (comp.getClientProperty("plugin") != null) { IControlCenterPlugin pl = (IControlCenterPlugin) comp.getClientProperty("plugin"); ((JButton) comp).setIcon(pl.getToolIcon(pl.equals(selplugin))); // ((JToggleButton)comp).setSelected(pluginname.equals(comp.getClientProperty("pluginname"))); } } toolbar.validate(); toolbar.repaint(); // If toolbar has been dropped out -> pack the window (hack???). Container root = toolbar; while (root.getParent() != null && !(root instanceof Window)) root = root.getParent(); if (root != null && !(root instanceof JFrame)) { ((Window) root).pack(); } }