<commit_before>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/

package org.vrjuggler.vrjconfig.controlpanel;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;

import org.vrjuggler.tweek.TweekCore;
import org.vrjuggler.tweek.beans.FileLoader;
import org.vrjuggler.tweek.beans.UndoHandler;
import org.vrjuggler.tweek.event.*;
import org.vrjuggler.tweek.services.GlobalPreferencesServiceProxy;
import org.vrjuggler.tweek.services.GlobalPreferencesService;
import org.vrjuggler.tweek.text.MessageDocument;

import org.vrjuggler.jccl.config.*;
import org.vrjuggler.jccl.rtrc.*;

import org.vrjuggler.vrjconfig.ui.ConnectionDialog;
import org.vrjuggler.vrjconfig.ui.ContextToolbar;


/**
 */
public class ControlPanelToolbar
   extends ContextToolbar
{
   public static final String NEW_ACTION      = "New";
   public static final String OPEN_ACTION     = "Open";
   public static final String RTRC_ACTION     = "RTRC";
   public static final String SAVE_ACTION     = "Save";
   public static final String SAVE_AS_ACTION  = "SaveAs";

   public ControlPanelToolbar(ConfigContext ctx, FileLoader fileLoader,
                              UndoHandler undoHandler)
   {
      super(ctx, fileLoader, undoHandler);

      try
      {
         GlobalPreferencesService prefs = new GlobalPreferencesServiceProxy();

         // Using the global user preferences from Tweek, set the start
         // directory for fileChooser.
         File f = new File(prefs.getChooserStartDir());
         fileChooser.setCurrentDirectory(f);
      }
      catch(Exception ex)
      {
         MessageDocument doc = TweekCore.instance().getMessageDocument();
         doc.printWarningnl("[ControlPanelToolbar()] WARNING: Failed to set " +
                            "file chooser start directory: " +
                            ex.getMessage());
      }

      try
      {
         jbInit();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }

      // Try to get icons for the toolbar buttons
      try
      {
         ClassLoader loader = getClass().getClassLoader();
         String img_root = "org/vrjuggler/vrjconfig/images";
         rtrcBtn.setIcon(new ImageIcon(loader.getResource(img_root +
                                                          "/vrjuggler.gif")));
      }
      catch (Exception e)
      {
         // Ack! No icons. Use text labels instead
         rtrcBtn.setText("RTRC");
      }

      toolbar.add(newBtn, null);
      toolbar.add(openBtn, null);
      toolbar.add(rtrcBtn, null);
      toolbar.add(saveBtn, null);
      toolbar.add(saveAsBtn, null);
      toolbar.addSeparator();
      toolbar.add(undoBtn, null);
      toolbar.add(redoBtn, null);
      toolbar.addSeparator();
      toolbar.add(Box.createHorizontalGlue(), null);
      toolbar.add(expandBtn, null);
   }

   public boolean doRTRC()
   {
      try
      {
         ConfigBroker broker = getBroker();
         RTRCDataSourceBroker RTRCBroker = new RTRCDataSourceBrokerProxy();
         ConnectionDialog dialog =
            new ConnectionDialog((Frame) getParentFrame(),
                                 "Remote Run-Time Reconfiguration Connections");
         dialog.setVisible(true);

         if ( dialog.getStatus() == ConnectionDialog.OK_OPTION )
         {
            RTRCDataSource data_src = dialog.getDataSource();

            broker.add(data_src.toString(), data_src);
            this.context.add(data_src.toString());

            fireAction(RTRC_ACTION);

            return true;
         }
      }
      catch (Exception ioe)
      {
         JOptionPane.showMessageDialog(getParentFrame(), ioe.getMessage(),
                                       "Error", JOptionPane.ERROR_MESSAGE);
         ioe.printStackTrace();
      }

      return false;
   }

   /**
    * JBuilder auto-generated GUI code.
    */
   private void jbInit()
      throws Exception
   {
      rtrcBtn.setToolTipText("Acquire the config elements of a running " +
                             "VR Juggler application");
      rtrcBtn.setActionCommand(RTRC_ACTION);
      rtrcBtn.setFocusPainted(false);
      rtrcBtn.addActionListener(new ActionListener()
      {
         public void actionPerformed(ActionEvent evt)
         {
            doRTRC();
         }
      });
   }

   // JBuilder GUI variables
   private JButton rtrcBtn = new JButton();
}
<commit_msg>Added a title bar similar to that provided by the toolbar type org.vrjuggler.vrjconfig.ui.ConfigToolbar.  I have written this so that a message will be displayed in the title bar when there are unsaved changes, but at the moment, the Control Panel does not keep track of that well enough to inform us.<commit_after>/*************** <auto-copyright.pl BEGIN do not edit this line> **************
 *
 * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
 *
 * Original Authors:
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>,
 *   <NAME>, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -----------------------------------------------------------------
 * File:          $RCSfile$
 * Date modified: $Date$
 * Version:       $Revision$
 * -----------------------------------------------------------------
 *
 *************** <auto-copyright.pl END do not edit this line> ***************/

package org.vrjuggler.vrjconfig.controlpanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;

import org.vrjuggler.tweek.TweekCore;
import org.vrjuggler.tweek.beans.FileLoader;
import org.vrjuggler.tweek.beans.UndoHandler;
import org.vrjuggler.tweek.event.*;
import org.vrjuggler.tweek.services.GlobalPreferencesServiceProxy;
import org.vrjuggler.tweek.services.GlobalPreferencesService;
import org.vrjuggler.tweek.text.MessageDocument;

import org.vrjuggler.jccl.config.*;
import org.vrjuggler.jccl.rtrc.*;

import org.vrjuggler.vrjconfig.ui.ConnectionDialog;
import org.vrjuggler.vrjconfig.ui.ContextToolbar;


/**
 */
public class ControlPanelToolbar
   extends ContextToolbar
{
   public static final String NEW_ACTION      = "New";
   public static final String OPEN_ACTION     = "Open";
   public static final String RTRC_ACTION     = "RTRC";
   public static final String SAVE_ACTION     = "Save";
   public static final String SAVE_AS_ACTION  = "SaveAs";

   private static final String SAVED_STATE_TEXT   = "";
   private static final String UNSAVED_STATE_TEXT = "Unsaved Changes";

   public ControlPanelToolbar(ConfigContext ctx, FileLoader fileLoader,
                              UndoHandler undoHandler)
   {
      super(ctx, fileLoader, undoHandler);

      try
      {
         GlobalPreferencesService prefs = new GlobalPreferencesServiceProxy();

         // Using the global user preferences from Tweek, set the start
         // directory for fileChooser.
         File f = new File(prefs.getChooserStartDir());
         fileChooser.setCurrentDirectory(f);
      }
      catch(Exception ex)
      {
         MessageDocument doc = TweekCore.instance().getMessageDocument();
         doc.printWarningnl("[ControlPanelToolbar()] WARNING: Failed to set " +
                            "file chooser start directory: " +
                            ex.getMessage());
      }

      try
      {
         jbInit();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }

      // Try to get icons for the toolbar buttons
      try
      {
         ClassLoader loader = getClass().getClassLoader();
         String img_root = "org/vrjuggler/vrjconfig/images";
         rtrcBtn.setIcon(new ImageIcon(loader.getResource(img_root +
                                                          "/vrjuggler.gif")));
      }
      catch (Exception e)
      {
         // Ack! No icons. Use text labels instead
         rtrcBtn.setText("RTRC");
      }

      toolbar.add(newBtn, null);
      toolbar.add(openBtn, null);
      toolbar.add(rtrcBtn, null);
      toolbar.add(saveBtn, null);
      toolbar.add(saveAsBtn, null);
      toolbar.addSeparator();
      toolbar.add(undoBtn, null);
      toolbar.add(redoBtn, null);
      toolbar.addSeparator();
      toolbar.add(Box.createHorizontalGlue(), null);
      toolbar.add(expandBtn, null);
   }

   public boolean doSave()
   {
      boolean saved = super.doSave();
      stateLabel.setText(saved ? SAVED_STATE_TEXT : UNSAVED_STATE_TEXT);
      return saved;
   }

   public boolean doSaveAs()
   {
      boolean saved = super.doSaveAs();
      stateLabel.setText(saved ? SAVED_STATE_TEXT : UNSAVED_STATE_TEXT);
      return saved;
   }

   public boolean doRTRC()
   {
      try
      {
         ConfigBroker broker = getBroker();
         RTRCDataSourceBroker RTRCBroker = new RTRCDataSourceBrokerProxy();
         ConnectionDialog dialog =
            new ConnectionDialog((Frame) getParentFrame(),
                                 "Remote Run-Time Reconfiguration Connections");
         dialog.setVisible(true);

         if ( dialog.getStatus() == ConnectionDialog.OK_OPTION )
         {
            RTRCDataSource data_src = dialog.getDataSource();

            broker.add(data_src.toString(), data_src);
            this.context.add(data_src.toString());

            fireAction(RTRC_ACTION);

            return true;
         }
      }
      catch (Exception ioe)
      {
         JOptionPane.showMessageDialog(getParentFrame(), ioe.getMessage(),
                                       "Error", JOptionPane.ERROR_MESSAGE);
         ioe.printStackTrace();
      }

      return false;
   }

   /**
    * JBuilder auto-generated GUI code.
    */
   private void jbInit()
      throws Exception
   {
      titlePanel.setLayout(new BorderLayout());
      titlePanel.setBorder(BorderFactory.createRaisedBevelBorder());
      titlePanel.setBackground(UIManager.getColor("textHighlight"));
      stateLabel.setBackground(UIManager.getColor("textHighlight"));
      stateLabel.setFont(new Font("Serif", Font.ITALIC, 18));
      stateLabel.setForeground(UIManager.getColor("textHighlightText"));
      stateLabel.setOpaque(true);
      stateLabel.setHorizontalAlignment(SwingConstants.LEFT);
      stateLabel.setText(SAVED_STATE_TEXT);
      titleLabel.setBackground(UIManager.getColor("textHighlight"));
      titleLabel.setFont(new Font("Serif", Font.BOLD, 18));
      titleLabel.setForeground(UIManager.getColor("textHighlightText"));
      titleLabel.setOpaque(true);
      titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
      titleLabel.setText("VRJConfig Control Panel");
      titlePanel.add(stateLabel, BorderLayout.WEST);
      titlePanel.add(titleLabel, BorderLayout.EAST);
      this.add(titlePanel, BorderLayout.NORTH);
      rtrcBtn.setToolTipText("Acquire the config elements of a running " +
                             "VR Juggler application");
      rtrcBtn.setActionCommand(RTRC_ACTION);
      rtrcBtn.setFocusPainted(false);
      rtrcBtn.addActionListener(new ActionListener()
      {
         public void actionPerformed(ActionEvent evt)
         {
            doRTRC();
         }
      });
   }

   // JBuilder GUI variables
   private JPanel titlePanel = new JPanel();
   private JLabel stateLabel = new JLabel();
   private JLabel titleLabel = new JLabel();
   private JButton rtrcBtn = new JButton();
}

{'fraction_non_alphanumeric': 0.11976267213595078, 'fraction_numerical': 0.00366246703779666, 'mean_word_length': 2.46875, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2658346', 'n_tokens_mistral': 3851, 'n_tokens_neox': 3763, 'n_words': 963}