Search in sources :

Example 26 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project gradle by gradle.

the class SinglePaneUIInstance method createCenterPanel.

private Component createCenterPanel() {
    splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitter.setTopComponent(createMainGradlePanel());
    splitter.setBottomComponent(outputPanelLord.getMainPanel());
    splitter.setContinuousLayout(true);
    //This little bit of tedium is so we can set our size based on window's size. This listens
    //for when the window is actually shown. It then adds a listen to store the location.
    splitter.addHierarchyListener(new HierarchyListener() {

        public void hierarchyChanged(HierarchyEvent e) {
            if (HierarchyEvent.SHOWING_CHANGED == (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED)) {
                //we only want the first one of these, so remove ourselves as a listener.
                splitter.removeHierarchyListener(this);
                Window window = SwingUtilities.getWindowAncestor(splitter);
                if (window != null) {
                    Dimension dimension = window.getSize();
                    //we'll just make ourselves half the height of the window
                    int halfHeight = dimension.height / 2;
                    splitter.setDividerLocation(halfHeight);
                }
                PreferencesAssistant.restoreSettings(settings, splitter, SPLITTER_PREFERENCES_ID, SinglePaneUIInstance.class);
                //Now that we're visible, this is so we save the location when the splitter is moved.
                splitter.addPropertyChangeListener(new PropertyChangeListener() {

                    public void propertyChange(PropertyChangeEvent evt) {
                        if (JSplitPane.DIVIDER_LOCATION_PROPERTY.equals(evt.getPropertyName())) {
                            PreferencesAssistant.saveSettings(settings, splitter, SPLITTER_PREFERENCES_ID, SinglePaneUIInstance.class);
                        }
                    }
                });
            }
        }
    });
    //this keeps the bottom the same size when resizing the window. Extra space is added/removed from the top.
    splitter.setResizeWeight(1);
    return splitter;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Example 27 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project gephi by gephi.

the class GraphFileExporterUI method action.

@Override
public void action() {
    final String LAST_PATH = "GraphFileExporterUI_Last_Path";
    final String LAST_PATH_DEFAULT = "GraphFileExporterUI_Last_Path_Default";
    final ExportControllerUI exportController = Lookup.getDefault().lookup(ExportControllerUI.class);
    if (exportController == null) {
        return;
    }
    //Get last directory
    String lastPathDefault = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_PATH_DEFAULT, null);
    String lastPath = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_PATH, lastPathDefault);
    //Options panel
    FlowLayout layout = new FlowLayout(FlowLayout.RIGHT);
    JPanel optionsPanel = new JPanel(layout);
    final JButton optionsButton = new JButton(NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_optionsButton_name"));
    optionsPanel.add(optionsButton);
    optionsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ExporterUI exporterUI = exportController.getExportController().getUI(selectedExporter);
            if (exporterUI != null) {
                JPanel panel = exporterUI.getPanel();
                exporterUI.setup(selectedExporter);
                DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_optionsDialog_title", selectedBuilder.getName()));
                TopDialog topDialog = new TopDialog(dialog, dd.getTitle(), dd.isModal(), dd, dd.getClosingOptions(), dd.getButtonListener());
                topDialog.setVisible(true);
                Object result = (dd.getValue() != null) ? dd.getValue() : NotifyDescriptor.CLOSED_OPTION;
                //                    Object result = DialogDisplayer.getDefault().notify(dd);
                exporterUI.unsetup(result == NotifyDescriptor.OK_OPTION);
            }
        }
    });
    //Graph Settings Panel
    final JPanel southPanel = new JPanel(new BorderLayout());
    southPanel.add(optionsPanel, BorderLayout.NORTH);
    GraphFileExporterUIPanel graphSettings = new GraphFileExporterUIPanel();
    graphSettings.setVisibleOnlyGraph(visibleOnlyGraph);
    southPanel.add(graphSettings, BorderLayout.CENTER);
    //Optionable file chooser
    final JFileChooser chooser = new JFileChooser(lastPath) {

        @Override
        protected JDialog createDialog(Component parent) throws HeadlessException {
            dialog = super.createDialog(parent);
            dialog.setSize(640, 480);
            dialog.setResizable(true);
            Component c = dialog.getContentPane().getComponent(0);
            if (c != null && c instanceof JComponent) {
                Insets insets = ((JComponent) c).getInsets();
                southPanel.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
            }
            dialog.getContentPane().add(southPanel, BorderLayout.SOUTH);
            return dialog;
        }

        @Override
        public void approveSelection() {
            if (canExport(this)) {
                super.approveSelection();
            }
        }
    };
    chooser.setDialogTitle(NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_filechooser_title"));
    chooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            DialogFileFilter fileFilter = (DialogFileFilter) evt.getNewValue();
            //Options panel enabling
            selectedBuilder = getExporter(fileFilter);
            if (selectedBuilder != null) {
                selectedExporter = selectedBuilder.buildExporter();
            }
            if (selectedBuilder != null && exportController.getExportController().getUI(selectedExporter) != null) {
                optionsButton.setEnabled(true);
            } else {
                optionsButton.setEnabled(false);
            }
            //Selected file extension change
            if (selectedFile != null && fileFilter != null) {
                String fileName = selectedFile.getName();
                String directoryPath = chooser.getCurrentDirectory().getAbsolutePath();
                if (fileName.lastIndexOf(".") != -1) {
                    fileName = fileName.substring(0, fileName.lastIndexOf("."));
                    fileName = fileName.concat(fileFilter.getExtensions().get(0));
                    selectedFile = new File(directoryPath, fileName);
                    chooser.setSelectedFile(selectedFile);
                }
            }
        }
    });
    chooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue() != null) {
                selectedFile = (File) evt.getNewValue();
            }
        }
    });
    //File filters
    DialogFileFilter defaultFilter = null;
    for (GraphFileExporterBuilder graphFileExporter : Lookup.getDefault().lookupAll(GraphFileExporterBuilder.class)) {
        for (FileType fileType : graphFileExporter.getFileTypes()) {
            DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
            dialogFileFilter.addExtensions(fileType.getExtensions());
            if (defaultFilter == null) {
                defaultFilter = dialogFileFilter;
            }
            chooser.addChoosableFileFilter(dialogFileFilter);
        }
    }
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(defaultFilter);
    selectedFile = new File(chooser.getCurrentDirectory(), "Untitled" + defaultFilter.getExtensions().get(0));
    chooser.setSelectedFile(selectedFile);
    //Show
    int returnFile = chooser.showSaveDialog(null);
    if (returnFile == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        file = FileUtil.normalizeFile(file);
        FileObject fileObject = FileUtil.toFileObject(file);
        //Save last path
        NbPreferences.forModule(GraphFileExporterUI.class).put(LAST_PATH, file.getAbsolutePath());
        //Save variable
        visibleOnlyGraph = graphSettings.isVisibleOnlyGraph();
        //Do
        selectedExporter.setExportVisible(visibleOnlyGraph);
        exportController.exportFile(fileObject, selectedExporter);
    }
    dialog = null;
}
Also used : JPanel(javax.swing.JPanel) GraphFileExporterBuilder(org.gephi.io.exporter.spi.GraphFileExporterBuilder) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) ExporterUI(org.gephi.io.exporter.spi.ExporterUI) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GraphFileExporterUIPanel(org.gephi.desktop.io.export.GraphFileExporterUIPanel) BorderLayout(java.awt.BorderLayout) FileObject(org.openide.filesystems.FileObject) JComponent(javax.swing.JComponent) Component(java.awt.Component) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) ExportControllerUI(org.gephi.desktop.io.export.ExportControllerUI) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) FileType(org.gephi.io.exporter.api.FileType) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 28 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project gephi by gephi.

the class EdgeSettingsPanel method setup.

public void setup() {
    VizModel vizModel = VizController.getInstance().getVizModel();
    vizModel.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("init")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeHasUniColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("showEdges")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeUniColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeInSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeOutSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeBothSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeScale")) {
                refreshSharedConfig();
            }
        }
    });
    refreshSharedConfig();
    showEdgesCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setShowEdges(showEdgesCheckbox.isSelected());
            setEnable(true);
        }
    });
    ((JColorButton) edgeColorButton).addPropertyChangeListener(JColorButton.EVENT_COLOR, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeUniColor(((JColorButton) edgeColorButton).getColorArray());
        }
    });
    sourceNodeColorCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeHasUniColor(!sourceNodeColorCheckbox.isSelected());
        }
    });
    selectionColorCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeSelectionColor(selectionColorCheckbox.isSelected());
        }
    });
    edgeInSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeInSelectionColor(edgeInSelectionColorChooser.getColor().getComponents(null));
        }
    });
    edgeBothSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeBothSelectionColor(edgeBothSelectionColorChooser.getColor().getComponents(null));
        }
    });
    edgeOutSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeOutSelectionColor(edgeOutSelectionColorChooser.getColor().getComponents(null));
        }
    });
    scaleSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            if (vizModel.getEdgeScale() != (scaleSlider.getValue() / 10f + 0.1f)) {
                vizModel.setEdgeScale(scaleSlider.getValue() / 10f + 0.1f);
            }
        }
    });
}
Also used : JColorButton(org.gephi.ui.components.JColorButton) VizModel(org.gephi.visualization.VizModel) PropertyChangeEvent(java.beans.PropertyChangeEvent) ItemEvent(java.awt.event.ItemEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) ActionEvent(java.awt.event.ActionEvent) ItemListener(java.awt.event.ItemListener) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Example 29 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project gephi by gephi.

the class VizModel method init.

public void init() {
    final PropertyChangeEvent evt = new PropertyChangeEvent(this, "init", null, null);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            if (listeners != null) {
                for (PropertyChangeListener l : listeners) {
                    l.propertyChange(evt);
                }
            }
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 30 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project gephi by gephi.

the class Module method install.

public static void install() {
    // don't install directory chooser if standard chooser is desired
    if (isStandardChooserForced()) {
        return;
    }
    final UIDefaults uid = UIManager.getDefaults();
    originalImpl = (Class<? extends FileChooserUI>) uid.getUIClass(KEY);
    Class impl = DelegatingChooserUI.class;
    final String val = impl.getName();
    // don't install dirchooser if quickfilechooser is present
    if (!isQuickFileChooser(uid.get(KEY))) {
        uid.put(KEY, val);
        // To make it work in NetBeans too:
        uid.put(val, impl);
    }
    // #61147: prevent NB from switching to a different UI later (under GTK):
    uid.addPropertyChangeListener(pcl = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            Object className = uid.get(KEY);
            if ((name.equals(KEY) || name.equals("UIDefaults")) && !val.equals(className) && !isQuickFileChooser(className)) {
                uid.put(KEY, val);
            }
        }
    });
}
Also used : UIDefaults(javax.swing.UIDefaults) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)574 PropertyChangeListener (java.beans.PropertyChangeListener)349 ActionEvent (java.awt.event.ActionEvent)42 JPanel (javax.swing.JPanel)36 ActionListener (java.awt.event.ActionListener)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)31 PropertyVetoException (java.beans.PropertyVetoException)24 JLabel (javax.swing.JLabel)24 File (java.io.File)23 BorderLayout (java.awt.BorderLayout)22 List (java.util.List)21 IOException (java.io.IOException)19 Dimension (java.awt.Dimension)16 ChangeEvent (javax.swing.event.ChangeEvent)15 PropertyChangeSupport (java.beans.PropertyChangeSupport)13 ChangeListener (javax.swing.event.ChangeListener)13 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)13 JScrollPane (javax.swing.JScrollPane)12 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)12