⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autoexportclient.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
字号:
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla.plugin.autoexport;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Map;
import java.util.TreeMap;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.rapla.components.layout.TableLayout;
import org.rapla.components.xmlbundle.I18nBundle;
import org.rapla.entities.configuration.Preferences;
import org.rapla.entities.configuration.RaplaMap;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;
import org.rapla.gui.MenuExtensionPoint;
import org.rapla.gui.RaplaGUIComponent;
import org.rapla.gui.internal.common.CalendarSelectionModel;
import org.rapla.gui.toolkit.DialogUI;
import org.rapla.plugin.RaplaExtensionPoints;
import org.rapla.plugin.abstractcalendar.AbstractHTMLCalendarPage;
/**
 */

public class AutoExportClient extends RaplaGUIComponent
{
    String text;
    I18nBundle pluginI18n;

    /*        availableURL = config.getChild("serverurl").getValue(null);
    if (availableURL != null)
        availableURL = ConfigTools.resolveContext(availableURL,context);*/
    public AutoExportClient(RaplaContext sm) throws RaplaException {
        super(sm);
        if ( !isModifyPreferencesAllowed() ) {
        	return;
        }
        setChildBundleName( AutoExportPlugin.RESOURCE_FILE);

        MenuExtensionPoint export = (MenuExtensionPoint) getService( RaplaExtensionPoints.EXPORT_MENU_EXTENSION_POINT);
        export.insert(createInfoMenu() );
        
        getLogger().info("Autoexport plugin added");
    }

    private JMenuItem createInfoMenu( )  {
        JMenuItem item = new JMenuItem( getString("autoexport.description") );
        item.setIcon( getIcon("icon.export") );
        item.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    try {
                    	CalendarSelectionModel model = ((CalendarSelectionModel)getContext().lookup(CalendarSelectionModel.ROLE));
                        export( (CalendarSelectionModel)model.clone(), getMainComponent());
                    } catch (Exception ex) {
                        showException( ex, getMainComponent() );
                    }
                }
        });
        return item;
    }


    public void export(final CalendarSelectionModel model,final Component parentComponent) throws Exception
    {
        final AutoExportOption option = new AutoExportOption(getContext());

        JPanel panel = new JPanel();
        final JTextField textField = new JTextField(20);
        final JTextField titleField = new JTextField(20);
        final JCheckBox showNavField = new JCheckBox();

        panel.setPreferredSize( new Dimension(600,300));
        panel.setLayout(new TableLayout( new double[][] {{TableLayout.PREFERRED,5,TableLayout.FILL},{TableLayout.PREFERRED,5,TableLayout.PREFERRED,5,TableLayout.PREFERRED,5,TableLayout.FILL}}));
        panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
        panel.add(new JLabel(getString("file.enter_name") +":"), "0,0");
        panel.add(textField, "2,0");

        panel.add(new JLabel(getString("weekview.print.title_textfield") +":"),"0,2");
        panel.add( titleField, "2,2");
        panel.add(new JLabel(getString("show_navigation")),"0,4");
        panel.add( showNavField, "2,4");
        panel.add( option.getComponent(), "0,6,2,6");
        option.setPreferences( getQuery().getPreferences());
        option.addButtons = false;
        option.show();
        showNavField.setSelected(  true );
        
        option.list.addListSelectionListener( new ListSelectionListener() {

            public void valueChanged( ListSelectionEvent e )
            {
                String filename = option.getSelectedFilename();
                if ( filename != null) {
                    textField.setText( filename );
                }
                CalendarSelectionModel model = option.getSelectedCalendarModel();
                if ( model != null ) {
                    String title = model.getTitle() ;
                    if ( title == null )
                    {
                        title = "";
                    }
                    titleField.setText(  title);
                    String showNav = (String) model.getOption( AbstractHTMLCalendarPage.SHOW_NAVIGATION_ENTRY );
                    boolean showNavFlag = showNav == null|| showNav.equals( "true" );
                    showNavField.setSelected( showNavFlag );
                }
            }

        });
        textField.addKeyListener( new KeyAdapter(){
            public void keyTyped(KeyEvent evt) {
                // need to update later because model is not filled on key Typed event
                SwingUtilities.invokeLater( new Runnable() {
                    public void run()
                    {
                        String filename =  textField.getText();
                        option.urlLabel.setText(  option.getAddress( filename));
                    }
                });
            }
        }
        );

        final DialogUI dlg = DialogUI.create(
                getContext(),
                                        parentComponent,false,panel,
                                       new String[] {
                                           getString("export")
                                           ,getString("cancel")
                                       });
        dlg.setTitle(getString("weekview.print.choose_export"));
        dlg.getButton(0).setIcon(getIcon("icon.export"));
        dlg.getButton(1).setIcon(getIcon("icon.cancel"));
        dlg.getButton(0).setAction( new AbstractAction() {
            private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent e) {
                String filename = textField.getText().trim();
                if (filename.length() == 0)
                {
                    showWarning(getString("error.no_name"), parentComponent);
                    return;
                }
                dlg.close();
                
                try 
                {
                    Preferences clone = newEditablePreferences();
                    Map exportMap= ((RaplaMap)clone.getEntry(AutoExportPlugin.PLUGIN_ENTRY));
                    Map newMap;
                    if ( exportMap == null)
                        newMap = new TreeMap();
                    else
                        newMap = new TreeMap( exportMap);
                    String title = titleField.getText().trim();
                    if ( title.length() > 0)
                        model.setTitle( title );
                    else
                        model.setTitle( null);
                    
                    String showNavEntry = showNavField.isSelected() ? "true" : "false";
                    model.setOption( AbstractHTMLCalendarPage.SHOW_NAVIGATION_ENTRY, showNavEntry);
                    newMap.put(filename, model.createConfiguration());
                    clone.putEntry( AutoExportPlugin.PLUGIN_ENTRY, getModification().newRaplaMap( newMap ));
                    getModification().store(clone);
                    DialogUI info = DialogUI.create(getContext(),parentComponent,false,getString("ok"),getString("hint_to_option"));
                    info.start();
                } 
                catch (RaplaException ex) 
                {
                    showException( ex, parentComponent);
                }
            }

        });
        dlg.start();
    }
    
    


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -