source/ui/optiondlg.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  The Contents of this file are made available subject to
00004  *  the terms of GNU Lesser General Public License Version 2.1.
00005  *
00006  *
00007  *    GNU Lesser General Public License Version 2.1
00008  *    =============================================
00009  *    Copyright 2005 by Kohei Yoshida.
00010  *    1039 Kingsway Dr., Apex, NC 27502, USA
00011  *
00012  *    This library is free software; you can redistribute it and/or
00013  *    modify it under the terms of the GNU Lesser General Public
00014  *    License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *    This library is distributed in the hope that it will be useful,
00017  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *    Lesser General Public License for more details.
00020  *
00021  *    You should have received a copy of the GNU Lesser General Public
00022  *    License along with this library; if not, write to the Free Software
00023  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *    MA  02111-1307  USA
00025  *
00026  ************************************************************************/
00027 
00028 #include "optiondlg.hxx"
00029 #include "unoglobal.hxx"
00030 #include "tool/global.hxx"
00031 #include "listener.hxx"
00032 #include "solver.hxx"
00033 
00034 #include <memory>
00035 
00036 #include "com/sun/star/awt/XCheckBox.hpp"
00037 
00038 #include "scsolver.hrc"
00039 
00040 using namespace ::com::sun::star;
00041 using namespace ::com::sun::star::uno;
00042 using ::std::auto_ptr;
00043 
00044 namespace scsolver {
00045 
00050 class OptionDlgOKAction : public ActionObject
00051 {
00052 public:
00053         OptionDlgOKAction()
00054         {
00055         }
00056 
00057         virtual ~OptionDlgOKAction() throw()
00058         {
00059         }
00060 
00061         virtual void execute( BaseDialog *dlg, const awt::ActionEvent& /*e*/ )
00062         {
00063                 OptionDialog* p = static_cast<OptionDialog*>(dlg);
00064                 p->setVisible(false);
00065         OptionData* pOption = p->getSolverImpl()->getOptionData();
00066         pOption->setModelType(p->getModelType());
00067         pOption->setVarPositive(p->isVarPositive());
00068         pOption->setVarInteger(p->isVarInteger());
00069         }
00070 };
00071 
00077 class OptionDlgWinCloseAction : public SimpleActionObject
00078 {
00079 public:
00080         virtual void execute( BaseDialog *dlg )
00081         {
00082                 dlg->close();
00083         }
00084 };
00085 
00086 //-----------------------------------------------------------------
00087 
00088 struct OptionDialogImpl
00089 {
00090         auto_ptr<ActionObject>       pActionOK;
00091         auto_ptr<SimpleActionObject> pActionWinClose;
00092 
00093         TopWindowListener* pTopWinListener;
00094         ActionListener*    pOKListener;
00095         CloseBtnListener*  pCloseListener;
00096 };
00097 
00098 //-----------------------------------------------------------------
00099 
00100 OptionDialog::OptionDialog( SolverImpl* p ) :
00101         BaseDialog( p ),
00102         m_pImpl( new OptionDialogImpl )
00103 {
00104         initialize();
00105 }
00106 
00107 OptionDialog::~OptionDialog() throw()
00108 {
00109 }
00110 
00111 void OptionDialog::initialize()
00112 {
00113         int nWidth = 200, nHeight = 150;
00114         initializeDefault( 
00115                 static_cast<sal_Int16>(nWidth), static_cast<sal_Int16>(nHeight), 
00116                 getResStr(SCSOLVER_STR_OPTIONDLG_TITLE) );
00117 
00118         sal_Int32 nX = 5, nY = 5, nMargin = 5;
00119 
00120         addFixedLine( nX, nY, nWidth-nX-nMargin, 12, ascii("flOptions"), 
00121                                   getResStr(SCSOLVER_STR_OPTIONDLG_TITLE) );
00122         nY += 13;
00123         addCheckBox( nX, nY+2, nWidth-nX-nMargin, 12, ascii("cbLinear"),
00124                                  getResStr(SCSOLVER_STR_OPTION_ASSUME_LINEAR) );
00125 
00126     nY += 13;
00127         addCheckBox( nX, nY+2, nWidth-nX-nMargin, 12, ascii("cbPositiveValue"),
00128                  getResStr(SCSOLVER_STR_OPTION_VAR_POSITIVE) );
00129 
00130     nY += 13;
00131         addCheckBox( nX, nY+2, nWidth-nX-nMargin, 12, ascii("cbIntegerValue"),
00132                  getResStr(SCSOLVER_STR_OPTION_VAR_INTEGER) );
00133 
00134         addButton( nWidth-110, nHeight-20, 50, 15, ascii("btnOK"), 
00135                            getResStr(SCSOLVER_STR_BTN_OK) );
00136 
00137         addButton( nWidth-55, nHeight-20, 50, 15, ascii("btnCancel"), 
00138                            getResStr(SCSOLVER_STR_BTN_CANCEL) );
00139 
00140         registerListeners();
00141 }
00142 
00143 void OptionDialog::registerListeners()
00144 {
00145         m_pImpl->pActionOK.reset( new OptionDlgOKAction );
00146         m_pImpl->pOKListener = new ActionListener( this, m_pImpl->pActionOK.get() );
00147         registerListener( ascii("btnOK"), m_pImpl->pOKListener );
00148 
00149         m_pImpl->pCloseListener = new CloseBtnListener(this);
00150         registerListener( ascii("btnCancel"), m_pImpl->pCloseListener );
00151 
00152         m_pImpl->pActionWinClose.reset( new OptionDlgWinCloseAction );
00153         m_pImpl->pTopWinListener = new TopWindowListener(this);
00154         m_pImpl->pTopWinListener->setActionClosing(m_pImpl->pActionWinClose.get());
00155         registerListener( m_pImpl->pTopWinListener );
00156 }
00157 
00158 void OptionDialog::unregisterListeners() throw()
00159 {
00160         unregisterListener( ascii("btnOK"), m_pImpl->pOKListener );
00161         unregisterListener( ascii("btnCancel"), m_pImpl->pCloseListener );
00162         unregisterListener( m_pImpl->pTopWinListener );
00163 }
00164 
00165 bool OptionDialog::doneRangeSelection() const
00166 {
00167         return false;
00168 }
00169 
00170 void OptionDialog::close()
00171 {
00172         setVisible(false);
00173 }
00174 
00175 const rtl::OUString OptionDialog::getDialogName() const
00176 {
00177         return ascii("OptionDialog");
00178 }
00179 
00180 void OptionDialog::setVisible( bool b )
00181 {
00182         setVisibleDefault( b );
00183 }
00184 
00185 OptModelType OptionDialog::getModelType() const
00186 {
00187         Reference<uno::XInterface> oWgt = getWidgetByName( ascii("cbLinear") );
00188         Reference<awt::XCheckBox> xCB( oWgt, UNO_QUERY );
00189 
00190         return xCB->getState() ? OPTMODELTYPE_LP : OPTMODELTYPE_NLP;
00191 }
00192 
00193 void OptionDialog::setModelType( OptModelType type )
00194 {
00195         Reference<uno::XInterface> oWgt = getWidgetByName( ascii("cbLinear") );
00196         Reference<awt::XCheckBox> xCB( oWgt, UNO_QUERY );
00197         if ( type == OPTMODELTYPE_LP || type == OPTMODELTYPE_MILP )
00198                 xCB->setState(1);
00199         else
00200                 xCB->setState(0);
00201 }
00202 
00203 bool OptionDialog::isVarPositive() const
00204 {
00205     Reference<uno::XInterface> oWgt = getWidgetByName( ascii("cbPositiveValue") );
00206     Reference<awt::XCheckBox> xCB( oWgt, UNO_QUERY );
00207     return xCB->getState();
00208 }
00209 
00210 void OptionDialog::setVarPositive(bool b)
00211 {
00212     Reference<uno::XInterface> oWgt = getWidgetByName( ascii("cbPositiveValue") );
00213     Reference<awt::XCheckBox> xCB( oWgt, UNO_QUERY );
00214     xCB->setState(b);
00215 }
00216 
00217 bool OptionDialog::isVarInteger() const
00218 {
00219     Reference<uno::XInterface> oWgt = getWidgetByName( ascii("cbIntegerValue") );
00220     Reference<awt::XCheckBox> xCB( oWgt, UNO_QUERY );
00221     return xCB->getState();
00222 }
00223 
00224 void OptionDialog::setVarInteger(bool b)
00225 {
00226     Reference<uno::XInterface> oWgt = getWidgetByName( ascii("cbIntegerValue") );
00227     Reference<awt::XCheckBox> xCB( oWgt, UNO_QUERY );
00228     xCB->setState(b);
00229 }
00230 
00231 }

Generated on Mon Jul 28 09:13:20 2008 for scsolver by  doxygen 1.5.3