/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.clothocad.tool.sequenceview;
import java.util.logging.Logger;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
//import org.openide.util.ImageUtilities;
import org.netbeans.api.settings.ConvertAsProperties;
/**
* Top component which displays something.
*/
@ConvertAsProperties(dtd = "-//org.clothocad.tool.sequenceview//SequenceView//EN",
autostore = false)
public final class SequenceViewTopComponent extends TopComponent {
private static SequenceViewTopComponent instance;
/** path to the icon used by the component and its open action */
// static final String ICON_PATH = "SET/PATH/TO/ICON/HERE";
private static final String PREFERRED_ID = "SequenceViewTopComponent";
public SequenceViewTopComponent() {
initComponents();
setName(NbBundle.getMessage(SequenceViewTopComponent.class, "CTL_SequenceViewTopComponent"));
setToolTipText(NbBundle.getMessage(SequenceViewTopComponent.class, "HINT_SequenceViewTopComponent"));
// setIcon(ImageUtilities.loadImage(ICON_PATH, true));
putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
}
public SequenceViewTopComponent(SequenceView sv) {
initComponents();
_sv=sv;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
/**
* Gets default instance. Do not use directly: reserved for *.settings files only,
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
* To obtain the singleton instance, use {@link #findInstance}.
*/
public static synchronized SequenceViewTopComponent getDefault() {
if (instance == null) {
instance = new SequenceViewTopComponent();
}
return instance;
}
/**
* Obtain the SequenceViewTopComponent instance. Never call {@link #getDefault} directly!
*/
public static synchronized SequenceViewTopComponent findInstance() {
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (win == null) {
Logger.getLogger(SequenceViewTopComponent.class.getName()).warning(
"Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
return getDefault();
}
if (win instanceof SequenceViewTopComponent) {
return (SequenceViewTopComponent) win;
}
Logger.getLogger(SequenceViewTopComponent.class.getName()).warning(
"There seem to be multiple components with the '" + PREFERRED_ID
+ "' ID. That is a potential source of errors and unexpected behavior.");
return getDefault();
}
@Override
public int getPersistenceType() {
return TopComponent.PERSISTENCE_ALWAYS;
}
@Override
public void componentOpened() {
// TODO add custom code on component opening
}
@Override
public void componentClosed() {
//if (!(_sv.getSaved())) {
//// ClothoDialogBox db = new ClothoDialogBox("Warning!", "Sequence View contains unsaved data! Close without saving?");
// String[] options = {"Yes Close", "No", "Save", "Hide"};
//// int chosen = db.show_optionDialog(javax.swing.JOptionPane.YES_NO_CANCEL_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE, options, options[2]);
// int chosen = javax.swing.JOptionPane.showOptionDialog(
// null,
// "Sequence View contains unsaved data! Close without saving?",
// "Warning!",
// javax.swing.JOptionPane.YES_NO_CANCEL_OPTION,
// javax.swing.JOptionPane.QUESTION_MESSAGE,
// null,
// options,
// options[2]);//FIXME replace with ClothoDialogBox
//
// if (chosen == javax.swing.JOptionPane.YES_OPTION) {
// // No longer clears data on close, since windows can be
// // re-opened after they are closed.
// // _connection.updateClearedSequence();
// SequenceTextPane.setText("");
// setTitle("Clotho: Sequence View (Address: " + _sv.getIndex() + ") New Sequence");
// CommentTextArea.setText("");
// OutputTextArea.setText("");
// _sv.updateWindowMenus();
//
// //FIXME _sv.loadPart(new clothodata.ClothoPartsData());
// if (_sv.getIsTC()) {
// _sv.getTCView().close();
// }
// this.dispose();
// } else if (chosen == javax.swing.JOptionPane.NO_OPTION) {
// this.requestFocus();
// } else if (chosen == 2) {
// this.requestFocus();
// _sv.saveSequence();
// } else if (chosen == 3) {
// if (_sv.getIsTC()) {
// _sv.getTCView().close();
// }
// this.dispose();
// }
// } else {
// if (_sv.getIsTC()) {
// _sv.getTCView().close();
// }
// this.dispose();
// }
}
void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty("version", "1.0");
// TODO store your settings
}
Object readProperties(java.util.Properties p) {
if (instance == null) {
instance = this;
}
instance.readPropertiesImpl(p);
return instance;
}
private void readPropertiesImpl(java.util.Properties p) {
String version = p.getProperty("version");
// TODO read your settings according to their version
}
@Override
protected String preferredID() {
return PREFERRED_ID;
}
private SequenceView _sv;
}