Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Commit

Permalink
Refactor preview ui model and rationalize the way how components comm…
Browse files Browse the repository at this point in the history
…unicate with it
  • Loading branch information
mbastian committed Sep 28, 2011
1 parent 01d2e38 commit 8861bd1
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ PreviewSettingsTopComponent.refreshButton.text=Refresh
PreviewSettingsTopComponent.labelPreset.text=Presets
PreviewSettingsTopComponent.ratio.minimum = Minimum
PreviewSettingsTopComponent.propertySheetTab = Settings

PreviewTopComponent.southBusyLabel.text=
PreviewTopComponent.backgroundButton.text=Background
PreviewTopComponent.resetZoomButton.text=Reset zoom
PreviewSettingsTopComponent.svgExportButton.text=SVG/PDF/PNG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ License, or (at your option) any later version.
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
import java.text.NumberFormat;
import java.util.logging.Logger;
Expand Down Expand Up @@ -58,7 +60,7 @@ License, or (at your option) any later version.
*
* @author Jérémy Subtil, Mathieu Bastian
*/
public final class PreviewSettingsTopComponent extends TopComponent {
public final class PreviewSettingsTopComponent extends TopComponent implements PropertyChangeListener {

private static PreviewSettingsTopComponent instance;
static final String ICON_PATH = "org/gephi/desktop/preview/resources/settings.png";
Expand Down Expand Up @@ -94,16 +96,6 @@ private PreviewSettingsTopComponent() {
propertiesPanel.add(propertySheet, BorderLayout.CENTER);
}


// checks the state of the workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
if (pc.getCurrentWorkspace() != null) {
enableRefreshButton();
}

// forces the controller instanciation
PreviewUIController puic = Lookup.getDefault().lookup(PreviewUIController.class);

//Ratio
ratioSlider.addChangeListener(new ChangeListener() {

Expand All @@ -116,6 +108,8 @@ public void stateChanged(ChangeEvent e) {
} else {
ratioLabel.setText(formatter.format(val));
}
PreviewUIController puic = Lookup.getDefault().lookup(PreviewUIController.class);
puic.setVisibilityRatio(getVisibilityRatio());
}
});

Expand All @@ -142,13 +136,41 @@ public void actionPerformed(ActionEvent e) {
ui.action();
}
});
refreshModel();
setup(null);

PreviewUIController controller = Lookup.getDefault().lookup(PreviewUIController.class);
controller.addPropertyChangeListener(this);

PreviewUIModel m = controller.getModel();
if (m != null) {
setup(m);
enableRefreshButton();
}
}

public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(PreviewUIController.SELECT)) {
PreviewUIModel model = (PreviewUIModel) evt.getNewValue();
setup(model);
if (model != null) {
enableRefreshButton();
} else {
disableRefreshButton();
}
} else if (evt.getPropertyName().equals(PreviewUIController.REFRESHED)) {
} else if (evt.getPropertyName().equals(PreviewUIController.REFRESHING)) {
boolean refrehsing = (Boolean) evt.getNewValue();
if (refrehsing) {
disableRefreshButton();
} else {
enableRefreshButton();
}
}
}

public void refreshModel() {
public void setup(PreviewUIModel previewModel) {
propertySheet.setNodes(new Node[]{new PreviewNode(propertySheet)});
PreviewUIController previewUIController = Lookup.getDefault().lookup(PreviewUIController.class);
PreviewUIModel previewModel = previewUIController.getModel();
if (previewModel != null) {
ratioSlider.setValue((int) (previewModel.getVisibilityRatio() * 100));
}
Expand Down Expand Up @@ -208,6 +230,9 @@ public void refreshModel() {
}
}
}

public void unsetup() {
}

/**
* Returns the graph visibility ratio set in the visibilityRatioSpinner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JLabel" name="southBusyLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/desktop/preview/Bundle.properties" key="PreviewTopComponent.southBusyLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new JXBusyLabel(new Dimension(14,14))"/>
</AuxValues>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ License, or (at your option) any later version.
*
* @author Jérémy Subtil, Mathieu Bastian
*/
public final class PreviewTopComponent extends TopComponent {
public final class PreviewTopComponent extends TopComponent implements PropertyChangeListener {

private static PreviewTopComponent instance;
static final String ICON_PATH = "org/gephi/desktop/preview/resources/preview.png";
private static final String PREFERRED_ID = "PreviewTopComponent";
private final transient ProcessingListener processingListener = new ProcessingListener();
//Data
private transient PreviewUIModel model;
private transient ProcessingTarget target;
private transient PApplet sketch;

Expand Down Expand Up @@ -106,17 +107,36 @@ public void actionPerformed(ActionEvent e) {
target.zoomMinus();
}
});

PreviewUIController controller = Lookup.getDefault().lookup(PreviewUIController.class);
controller.addPropertyChangeListener(this);

PreviewUIModel m = controller.getModel();
if (m != null) {
this.model = m;
initTarget(model);
}
}

public void refreshModel() {
PreviewUIController puic = Lookup.getDefault().lookup(PreviewUIController.class);
PreviewUIModel previewUIModel = puic.getModel();
if (previewUIModel == null) {
//Disable
initTarget(null);
} else {
initTarget(previewUIModel);
refreshPreview();
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(PreviewUIController.SELECT)) {
this.model = (PreviewUIModel) evt.getNewValue();
initTarget(model);
} else if (evt.getPropertyName().equals(PreviewUIController.REFRESHED)) {
SwingUtilities.invokeLater(new Runnable() {

public void run() {
target.refresh();
}
});
} else if (evt.getPropertyName().equals(PreviewUIController.REFRESHING)) {
setRefresh((Boolean) evt.getNewValue());
} else if (evt.getPropertyName().equals(PreviewUIController.GRAPH_CHANGED)) {
if ((Boolean) evt.getNewValue()) {
showBannerPanel();
} else {
hideBannerPanel();
}
}
}

Expand Down Expand Up @@ -180,12 +200,16 @@ public void run() {
* @see PreviewUIController#showRefreshNotification()
*/
public void showBannerPanel() {
bannerPanel.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {

public void run() {
bannerPanel.setVisible(true);
}
});
}

public void setBackgroundColor(Color color) {
((JColorButton) backgroundButton).setColor(color);

}

/**
Expand All @@ -194,7 +218,12 @@ public void setBackgroundColor(Color color) {
* @see PreviewUIController#hideRefreshNotification()
*/
public void hideBannerPanel() {
bannerPanel.setVisible(false);
SwingUtilities.invokeLater(new Runnable() {

public void run() {
bannerPanel.setVisible(false);
}
});
}

/** This method is called from within the constructor to
Expand All @@ -221,8 +250,6 @@ private void initComponents() {
plusButton = new javax.swing.JButton();

setLayout(new java.awt.GridBagLayout());

org.openide.awt.Mnemonics.setLocalizedText(southBusyLabel, org.openide.util.NbBundle.getMessage(PreviewTopComponent.class, "PreviewTopComponent.southBusyLabel.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
Expand Down Expand Up @@ -412,16 +439,4 @@ public Object readResolve() {
return PreviewTopComponent.getDefault();
}
}

/**
* Refresh the preview applet.
*/
private void refreshPreview() {
SwingUtilities.invokeLater(new Runnable() {

public void run() {
target.refresh();
}
});
}
}
Loading

0 comments on commit 8861bd1

Please sign in to comment.