/* * Copyright (c) 2010 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.. */ package org.clothocore.widget.fabdash; import java.util.ArrayList; import java.util.logging.Logger; import javax.swing.SwingUtilities; import org.clothocore.api.core.Collator; import org.clothocore.api.core.Collector; import org.clothocore.api.core.wrapper.ConnectionWrapper; //import org.clothocore.api.data.Feature; import org.clothocore.api.core.wrapper.PluginWrapper; import org.clothocore.api.core.wrapper.ToolWrapper; import org.clothocore.api.data.ObjType; //import org.clothocore.widget.fabdash.browser.ObjTypeChooser; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; import org.netbeans.api.settings.ConvertAsProperties; import org.openide.awt.StatusDisplayer; @ConvertAsProperties(dtd = "-//org.clothocore.widget.fabdash//Inventory//EN", autostore = false) public final class InventoryTopComponent extends TopComponent { private static InventoryTopComponent 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 = "InventoryTopComponent"; public InventoryTopComponent() { initComponents(); if (Collator.getPreference("preferredConnection").equals("configurable")) { localRadioButton.setSelected(true); configurableRadioButton.setSelected(false); } else if (Collator.getPreference("preferredConnection").equals("local")) { localRadioButton.setSelected(true); configurableRadioButton.setSelected(false); } else { localRadioButton.setSelected(true); configurableRadioButton.setSelected(false); } this.setDisplayName("Log In"); changeButton.setEnabled(false); StatusDisplayer.getDefault().setStatusText("Not connected to Clotho connection"); currentUserLabel.setText("Not connected"); setName(NbBundle.getMessage(InventoryTopComponent.class, "CTL_InventoryTopComponent")); setToolTipText(NbBundle.getMessage(InventoryTopComponent.class, "HINT_InventoryTopComponent")); // setIcon(ImageUtilities.loadImage(ICON_PATH, true)); putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE); if (Collator.getPreference("launchAtStart").equals("true")) { autoCheckbox.setSelected(true); connect(); } else { autoCheckbox.setSelected(false); } } public void changeObjType(ObjType type) { _chosenType = type; System.out.println(_chosenType); } private void refreshConnectionInformation() { if (Collector.isConnected()) { if (Collector.getCurrentUser() != null) { currentUserLabel.setText(Collector.getCurrentUser().getDisplayName()); } } else { currentUserLabel.setText("Not Connected"); StatusDisplayer.getDefault().setStatusText("Not connected to Clotho connection"); } } /** 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() { backgroundPanel = new javax.swing.JPanel(); connectionPanel = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); currentUserLabel = new javax.swing.JLabel(); connectButton = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); localRadioButton = new javax.swing.JRadioButton(); configurableRadioButton = new javax.swing.JRadioButton(); autoCheckbox = new javax.swing.JCheckBox(); changeButton = new javax.swing.JButton(); configureButton = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); setDisplayName(org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.displayName")); // NOI18N setLayout(new java.awt.BorderLayout()); backgroundPanel.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { backgroundPanelKeyTyped(evt); } }); connectionPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); connectionPanel.setMaximumSize(new java.awt.Dimension(900, 900)); connectionPanel.setMinimumSize(new java.awt.Dimension(150, 100)); connectionPanel.setPreferredSize(new java.awt.Dimension(150, 100)); jLabel1.setFont(new java.awt.Font("Ubuntu", 0, 12)); org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.jLabel1.text")); // NOI18N currentUserLabel.setFont(new java.awt.Font("Ubuntu", 0, 12)); org.openide.awt.Mnemonics.setLocalizedText(currentUserLabel, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.currentUserLabel.text")); // NOI18N currentUserLabel.setToolTipText(org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.currentUserLabel.toolTipText")); // NOI18N currentUserLabel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); currentUserLabel.setMaximumSize(new java.awt.Dimension(80, 25)); currentUserLabel.setMinimumSize(new java.awt.Dimension(80, 25)); currentUserLabel.setPreferredSize(new java.awt.Dimension(80, 25)); connectButton.setFont(new java.awt.Font("Ubuntu", 0, 10)); org.openide.awt.Mnemonics.setLocalizedText(connectButton, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.connectButton.text")); // NOI18N connectButton.setToolTipText(org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.connectButton.toolTipText")); // NOI18N connectButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { connectButtonActionPerformed(evt); } }); jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel1.setToolTipText(org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.jPanel1.toolTipText")); // NOI18N jPanel1.setMaximumSize(new java.awt.Dimension(250, 50)); jPanel1.setMinimumSize(new java.awt.Dimension(250, 50)); jPanel1.setPreferredSize(new java.awt.Dimension(250, 50)); localRadioButton.setFont(new java.awt.Font("Ubuntu", 0, 12)); org.openide.awt.Mnemonics.setLocalizedText(localRadioButton, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.localRadioButton.text")); // NOI18N localRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.localRadioButton.toolTipText")); // NOI18N localRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { localRadioButtonActionPerformed(evt); } }); configurableRadioButton.setFont(new java.awt.Font("Ubuntu", 0, 12)); org.openide.awt.Mnemonics.setLocalizedText(configurableRadioButton, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.configurableRadioButton.text")); // NOI18N configurableRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.configurableRadioButton.toolTipText")); // NOI18N configurableRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { configurableRadioButtonActionPerformed(evt); } }); autoCheckbox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(autoCheckbox, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.autoCheckbox.text")); // NOI18N autoCheckbox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { autoCheckboxActionPerformed(evt); } }); autoCheckbox.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { autoCheckboxPropertyChange(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(6, 6, 6) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(localRadioButton) .addComponent(configurableRadioButton))) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(autoCheckbox))) .addContainerGap(32, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(configurableRadioButton, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(11, 11, 11) .addComponent(localRadioButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(autoCheckbox) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); changeButton.setFont(new java.awt.Font("Ubuntu", 0, 10)); org.openide.awt.Mnemonics.setLocalizedText(changeButton, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.changeButton.text")); // NOI18N changeButton.setToolTipText(org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.changeButton.toolTipText")); // NOI18N changeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { changeButtonActionPerformed(evt); } }); configureButton.setFont(new java.awt.Font("Ubuntu", 0, 10)); org.openide.awt.Mnemonics.setLocalizedText(configureButton, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.configureButton.text")); // NOI18N configureButton.setToolTipText(org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.configureButton.toolTipText")); // NOI18N configureButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { configureButtonActionPerformed(evt); } }); javax.swing.GroupLayout connectionPanelLayout = new javax.swing.GroupLayout(connectionPanel); connectionPanel.setLayout(connectionPanelLayout); connectionPanelLayout.setHorizontalGroup( connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(connectionPanelLayout.createSequentialGroup() .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(connectionPanelLayout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(currentUserLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)) .addGroup(connectionPanelLayout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(changeButton) .addComponent(connectButton) .addComponent(configureButton)) .addContainerGap(13, Short.MAX_VALUE)) ); connectionPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {changeButton, configureButton, connectButton}); connectionPanelLayout.setVerticalGroup( connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(connectionPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(connectionPanelLayout.createSequentialGroup() .addComponent(changeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(6, 6, 6) .addComponent(connectButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(4, 4, 4) .addComponent(configureButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(connectionPanelLayout.createSequentialGroup() .addGroup(connectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(currentUserLabel, 0, 0, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/clothocore/widget/fabdash/browser/logo.png"))); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(InventoryTopComponent.class, "InventoryTopComponent.jLabel2.text")); // NOI18N jLabel2.setMinimumSize(new java.awt.Dimension(150, 100)); jLabel2.setPreferredSize(new java.awt.Dimension(150, 100)); javax.swing.GroupLayout backgroundPanelLayout = new javax.swing.GroupLayout(backgroundPanel); backgroundPanel.setLayout(backgroundPanelLayout); backgroundPanelLayout.setHorizontalGroup( backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(connectionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE) .addGroup(backgroundPanelLayout.createSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); backgroundPanelLayout.setVerticalGroup( backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(backgroundPanelLayout.createSequentialGroup() .addComponent(connectionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(65, Short.MAX_VALUE)) ); add(backgroundPanel, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectButtonActionPerformed connect(); }//GEN-LAST:event_connectButtonActionPerformed private void connect() { StatusDisplayer.getDefault().setStatusText("Connecting... Please Wait"); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (localRadioButton.isSelected()) { String selectstring = "org.clothocad.connection.localconnection"; ConnectionWrapper cw = (ConnectionWrapper) Collator.getPluginByUUID(selectstring); Collator.setDefaultConnection(cw); Collector.connectToDefault(); refreshConnectionInformation(); StatusDisplayer.getDefault().setStatusText("Connected to Local Connection"); } else if (configurableRadioButton.isSelected()) { String selectstring = "org.clothocad.connection.configurableconnection-ClothoConnection"; ConnectionWrapper cw = (ConnectionWrapper) Collator.getPluginByUUID(selectstring); Collator.setDefaultConnection(cw); Collector.connectToDefault(); refreshConnectionInformation(); StatusDisplayer.getDefault().setStatusText("Connected to Configurable Connection"); } if (Collector.isConnected()) { // localRadioButton.setEnabled(false); // configurableRadioButton.setEnabled(false); connectButton.setEnabled(false); // jPanel1.setEnabled(false); changeButton.setEnabled(true); } } }); } private void configurableRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configurableRadioButtonActionPerformed localRadioButton.setSelected(false); Collator.putPreference("preferredConnection", "configurable"); }//GEN-LAST:event_configurableRadioButtonActionPerformed private void localRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localRadioButtonActionPerformed configurableRadioButton.setSelected(false); Collator.putPreference("preferredConnection", "local"); }//GEN-LAST:event_localRadioButtonActionPerformed private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeButtonActionPerformed if (Collector.isConnected()) { UserFrame uf = new UserFrame(currentUserLabel); uf.pack(); uf.setVisible(true); } }//GEN-LAST:event_changeButtonActionPerformed private void backgroundPanelKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_backgroundPanelKeyTyped }//GEN-LAST:event_backgroundPanelKeyTyped private void configureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configureButtonActionPerformed ArrayList<ToolWrapper> allTools = Collator.getAllTools(); for (ToolWrapper tw : allTools) { if (tw.getUUID().equals("org.clothocad.tool.connectconfigtool-tool")) { tw.launchTool(); break; } } }//GEN-LAST:event_configureButtonActionPerformed private void autoCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoCheckboxActionPerformed }//GEN-LAST:event_autoCheckboxActionPerformed private void autoCheckboxPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_autoCheckboxPropertyChange if (autoCheckbox.isSelected()) { Collator.putPreference("launchAtStart", "true"); } else { Collator.putPreference("launchAtStart", "false"); } }//GEN-LAST:event_autoCheckboxPropertyChange // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox autoCheckbox; private javax.swing.JPanel backgroundPanel; private javax.swing.JButton changeButton; private javax.swing.JRadioButton configurableRadioButton; private javax.swing.JButton configureButton; private javax.swing.JButton connectButton; private javax.swing.JPanel connectionPanel; private javax.swing.JLabel currentUserLabel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JRadioButton localRadioButton; // 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 InventoryTopComponent getDefault() { if (instance == null) { instance = new InventoryTopComponent(); } return instance; } /** * Obtain the InventoryTopComponent instance. Never call {@link #getDefault} directly! */ public static synchronized InventoryTopComponent findInstance() { TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); if (win == null) { Logger.getLogger(InventoryTopComponent.class.getName()).warning( "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); return getDefault(); } if (win instanceof InventoryTopComponent) { return (InventoryTopComponent) win; } Logger.getLogger(InventoryTopComponent.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 //Called to populate the tree public void componentOpened() { } @Override public void componentClosed() { // TODO add custom code on component closing } 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 variables //// private ObjType _chosenType = ObjType.PART; }