/*
Copyright 2008-2010 Gephi
Authors : Eduardo Ramos <eduramiba@gmail.com>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.datalab.plugin.manipulators.general.ui;
import java.awt.Component;
import java.io.File;
import java.nio.charset.Charset;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.gephi.datalab.plugin.manipulators.general.ui.ImportCSVUIWizardAction.Mode;
import org.openide.WizardDescriptor;
import org.openide.util.HelpCtx;
public class ImportCSVUIWizardPanel2 implements WizardDescriptor.Panel {
private WizardDescriptor wizardDescriptor;
/**
* The visual component that displays this panel. If you need to access the
* component from this class, just use getComponent().
*/
private ImportCSVUIVisualPanel2 component;
// Get the visual component for the panel. In this template, the component
// is kept separate. This can be more efficient: if the wizard is created
// but never displayed, or not all panels are displayed, it is better to
// create only those which really need to be visible.
public Component getComponent() {
if (component == null) {
component = new ImportCSVUIVisualPanel2(this);
}
return component;
}
public HelpCtx getHelp() {
// Show no Help button for this panel:
return HelpCtx.DEFAULT_HELP;
// If you have context help:
// return new HelpCtx(SampleWizardPanel1.class);
}
public boolean isValid() {
return component.isValidCSV();
}
private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(1); // or can use ChangeSupport in NB 6.0
public final void addChangeListener(ChangeListener l) {
synchronized (listeners) {
listeners.add(l);
}
}
public final void removeChangeListener(ChangeListener l) {
synchronized (listeners) {
listeners.remove(l);
}
}
protected final void fireChangeEvent() {
Iterator<ChangeListener> it;
synchronized (listeners) {
it = new HashSet<ChangeListener>(listeners).iterator();
}
ChangeEvent ev = new ChangeEvent(this);
while (it.hasNext()) {
it.next().stateChanged(ev);
}
}
// You can use a settings object to keep track of state. Normally the
// settings object will be the WizardDescriptor, so you can use
// WizardDescriptor.getProperty & putProperty to store information entered
// by the user.
public void readSettings(Object settings) {
component.setSeparator((Character) wizardDescriptor.getProperty("separator"));
component.setFile((File) wizardDescriptor.getProperty("file"));
component.setMode((Mode) wizardDescriptor.getProperty("mode"));
component.setCharset((Charset) wizardDescriptor.getProperty("charset"));
component.reloadSettings();
}
public void unSetup() {
component.unSetup();
}
public void storeSettings(Object settings) {
wizardDescriptor.putProperty("columns-names", component.getColumnsToImport());
wizardDescriptor.putProperty("columns-types", component.getColumnsToImportTypes());
wizardDescriptor.putProperty("assign-new-node-ids", component.getAssignNewNodeIds());
wizardDescriptor.putProperty("create-new-nodes", component.getCreateNewNodes());
}
public void setWizardDescriptor(WizardDescriptor wizardDescriptor) {
this.wizardDescriptor = wizardDescriptor;
}
}