summaryrefslogtreecommitdiffstats
path: root/kdejava/koala/examples
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /kdejava/koala/examples
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdejava/koala/examples')
-rw-r--r--kdejava/koala/examples/kscribble/KPenBrushDlg.java82
-rw-r--r--kdejava/koala/examples/kscribble/KScribbleApp.java1039
-rw-r--r--kdejava/koala/examples/kscribble/KScribbleDoc.java300
-rw-r--r--kdejava/koala/examples/kscribble/KScribbleView.java342
-rw-r--r--kdejava/koala/examples/kscribble/Main.java78
-rw-r--r--kdejava/koala/examples/kscribble/Resource.java71
-rw-r--r--kdejava/koala/examples/simplemail/MailHelper.java220
-rw-r--r--kdejava/koala/examples/simplemail/README29
-rw-r--r--kdejava/koala/examples/simplemail/SimpleMailFrm.java240
-rw-r--r--kdejava/koala/examples/simplemail/SimpleMailer.java39
10 files changed, 2440 insertions, 0 deletions
diff --git a/kdejava/koala/examples/kscribble/KPenBrushDlg.java b/kdejava/koala/examples/kscribble/KPenBrushDlg.java
new file mode 100644
index 00000000..aabb0d3e
--- /dev/null
+++ b/kdejava/koala/examples/kscribble/KPenBrushDlg.java
@@ -0,0 +1,82 @@
+import java.util.*;
+
+import org.kde.qt.*;
+import org.kde.koala.*;
+
+/**
+ * The base class for JavaApiTest application windows. It sets up the main
+ * window and reads the config file as well as providing a menubar, toolbar
+ * and statusbar. An instance of KBaseView creates your center view, which is connected
+ * to the window's Doc object.
+ * KBase reimplements the methods that KMainWindow provides for main window handling and supports
+ * full session management as well as using KActions.
+ * @see KMainWindow
+ * @see KApplication
+ * @see KConfig
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 1.2 code generation
+ */
+public class KPenBrushDlg extends QDialog {
+
+ private QSpinBox width_spbox;
+ private QLabel width_label;
+ private QPushButton default_btn;
+ private QPushButton ok_btn;
+ private QPushButton cancel_btn;
+
+ public KPenBrushDlg(int curr, QWidget parent, String name) {
+ super (parent,name,true,WStyle_ContextHelp);
+ initDialog();
+ QWhatsThis.add(width_spbox,i18n("Select brush width"));
+
+ width_spbox.setValue(curr);
+ connect(default_btn, SIGNAL("clicked()"), this, SLOT("slotDefault()"));
+ connect(ok_btn, SIGNAL("clicked()"), this, SLOT("accept()"));
+ connect(cancel_btn, SIGNAL("clicked()"), this, SLOT("reject()"));
+
+
+ }
+
+ int getPenWidth() {
+ return width_spbox.value();
+ };
+
+ void initDialog(){
+ this.resize(370,210);
+ this.setMinimumSize(0,0);
+ width_spbox= new QSpinBox(this,"width_spbox");
+ width_spbox.setGeometry(150,50,100,25);
+ width_spbox.setMinimumSize(0,0);
+ width_spbox.setValue(1);
+ width_spbox.setRange(1,99);
+
+ width_label= new QLabel(this,"width_label");
+ width_label.setGeometry(20,50,120,25);
+ width_label.setMinimumSize(0,0);
+ width_label.setText(i18n("Pen width:"));
+
+ default_btn= new QPushButton(this,"default");
+ default_btn.setGeometry(30,160,100,30);
+ default_btn.setMinimumSize(0,0);
+ default_btn.setText(i18n("&Default"));
+ default_btn.setAutoDefault(true);
+
+ ok_btn= new QPushButton(this,"ok");
+ ok_btn.setGeometry(140,160,100,30);
+ ok_btn.setMinimumSize(0,0);
+ ok_btn.setText(i18n("&OK"));
+ ok_btn.setAutoDefault(true);
+
+ cancel_btn= new QPushButton(this,"cancel");
+ cancel_btn.setGeometry(250,160,100,30);
+ cancel_btn.setMinimumSize(0,0);
+ cancel_btn.setText(i18n("&Cancel"));
+ cancel_btn.setAutoDefault(true);
+
+ }
+
+ void slotDefault(){
+ width_spbox.setValue(3);
+ }
+}
diff --git a/kdejava/koala/examples/kscribble/KScribbleApp.java b/kdejava/koala/examples/kscribble/KScribbleApp.java
new file mode 100644
index 00000000..0085f655
--- /dev/null
+++ b/kdejava/koala/examples/kscribble/KScribbleApp.java
@@ -0,0 +1,1039 @@
+import java.util.*;
+import org.kde.qt.*;
+import org.kde.koala.*;
+
+/**
+ * The base class for KScribble application windows. It sets up the main
+ * window and reads the config file as well as providing a menubar, toolbar
+ * and statusbar. In initView(), your main view is created as the MDI child window manager.
+ * Child windows are created in createClient(), which gets a document instance as it's document to
+ * display whereby one document can have several views.The MDI child is an instance of KScribbleView,
+ * the document an instance of KScribbleDoc.
+ * KScribbleApp reimplements the methods that KMainWindow provides for main window handling and supports
+ * full session management as well as keyboard accelerator configuration by using KAccel.
+ * @see KMainWindow
+ * @see KApplication
+ * @see KConfig
+ * @see KAccel
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 1.1 code generation
+ */
+public class KScribbleApp extends KMainWindow implements Resource {
+
+ /** the configuration object of the application */
+ private KConfig config;
+ /** view is the main widget which represents your working area. The View
+ * class should handle all events of the view widget. It is kept empty so
+ * you can create your view according to your application's needs by
+ * changing the view class.
+ */
+ private KScribbleView view;
+ /** doc represents your actual document and is created only once. It keeps
+ * information such as filename and does the serialization of your files.
+ */
+ private KScribbleDoc doc;
+
+ /** contains the recently used filenames */
+ ArrayList recentFiles = null;
+
+ // menus
+ private QPopupMenu pFileMenu;
+ private QPopupMenu pEditMenu;
+ private QPopupMenu pPenMenu;
+ private QPopupMenu pViewMenu;
+ private QPopupMenu pWindowMenu;
+ private QPopupMenu pHelpMenu;
+ private QPopupMenu pRecentFileMenu;
+
+ private QWorkspace pWorkspace;
+ private QPrinter printer;
+ private int untitledCount = 0;
+ private ArrayList pDocList;
+ private KApplication kapp;
+ private KIconLoader k = new KIconLoader();
+
+ /** construtor of KScribbleApp, calls all init functions to create the application.
+ */
+ public KScribbleApp(QWidget parent, String name) {
+ super(parent,name, 0);
+ kapp = KApplication.kApplication();
+ config=kapp.config();
+
+ printer = new QPrinter();
+ untitledCount=0;
+ pDocList = new ArrayList();
+ setAcceptDrops(true);
+ ///////////////////////////////////////////////////////////////////
+ // call inits to invoke all other construction parts
+ initMenuBar();
+ initToolBar();
+ initStatusBar();
+ initKeyAccel();
+ initView();
+
+ readOptions();
+
+ ///////////////////////////////////////////////////////////////////
+ // disable menu and toolbar items at startup
+ disableCommand(ID_EDIT_UNDO);
+
+ }
+
+ public KScribbleApp() {
+ this(null, null);
+ }
+
+ /** initializes the KActions of the application */
+ protected void initKeyAccel() {
+
+ KAccel keyAccel = new KAccel(this);
+
+ // fileMenu accelerators
+ keyAccel.insert(KStdAccel.New, this, SLOT("slotFileNew()"));
+ keyAccel.insert(KStdAccel.Open, this, SLOT("slotFileOpen()"));
+ keyAccel.insert(KStdAccel.Save, this, SLOT("slotFileSave()"));
+ keyAccel.insert(KStdAccel.Close, this, SLOT("slotFileClose()"));
+ keyAccel.insert(KStdAccel.Print, this, SLOT("slotFilePrint()"));
+ keyAccel.insert(KStdAccel.Quit, this, SLOT("slotFileQuit()"));
+
+ // editMenu accelerators
+ keyAccel.insert(KStdAccel.Cut, this, SLOT("slotEditCut()"));
+ keyAccel.insert(KStdAccel.Copy, this, SLOT("slotEditCopy()"));
+ keyAccel.insert(KStdAccel.Paste, this, SLOT("slotEditPaste()"));
+
+ // help accelerator
+ keyAccel.insert(KStdAccel.Help, this, SLOT("appHelpActivated()"));
+
+ keyAccel.readSettings();
+
+ }
+
+
+ void initMenuBar() {
+ ///////////////////////////////////////////////////////////////////
+ // MENUBAR
+
+ pRecentFileMenu = new QPopupMenu(this);
+ connect(pRecentFileMenu, SIGNAL("activated(int)"), SLOT("slotFileOpenRecent(int)"));
+
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry file-Menu
+ pFileMenu = new QPopupMenu(this);
+
+
+ pFileMenu.insertItem(KDE.BarIconSet("filenew"),i18n("&New"), ID_FILE_NEW,-1);
+ pFileMenu.insertItem(KDE.BarIconSet("fileopen"),i18n("&Open..."), ID_FILE_OPEN,-1);
+ pFileMenu.insertItem(i18n("Open &recent"), pRecentFileMenu, ID_FILE_OPEN_RECENT,-1);
+
+ pFileMenu.insertItem(i18n("&Close"), ID_FILE_CLOSE,-1);
+ pFileMenu.insertSeparator();
+ pFileMenu.insertItem(KDE.BarIconSet("filefloppy") ,i18n("&Save"), ID_FILE_SAVE,-1);
+ pFileMenu.insertItem(i18n("Save &As..."), ID_FILE_SAVE_AS,-1);
+ pFileMenu.insertSeparator();
+ pFileMenu.insertItem(KDE.BarIconSet("fileprint"), i18n("&Print..."), ID_FILE_PRINT,-1);
+ pFileMenu.insertSeparator();
+ pFileMenu.insertItem(i18n("E&xit"), ID_FILE_QUIT,-1);
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry edit-Menu
+ pEditMenu = new QPopupMenu(this);
+ pEditMenu.insertItem(KDE.BarIconSet("undo"), i18n("&Undo"), ID_EDIT_UNDO,-1);
+ pEditMenu.insertSeparator();
+ pEditMenu.insertItem(KDE.BarIconSet("editcut"), i18n("Cu&t"), ID_EDIT_CUT,-1);
+ pEditMenu.insertItem(KDE.BarIconSet("editcopy"), i18n("&Copy"), ID_EDIT_COPY,-1);
+ pEditMenu.insertItem(KDE.BarIconSet("editpaste"), i18n("&Paste"), ID_EDIT_PASTE,-1);
+ pEditMenu.insertItem(KDE.BarIconSet("delete"),i18n("&Clear All"), ID_EDIT_CLEAR_ALL,-1);
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry pen-Menu
+ pPenMenu = new QPopupMenu();
+ pPenMenu.insertItem(i18n("&Color"), ID_PEN_COLOR,-1);
+ pPenMenu.insertItem(i18n("&Brush"), ID_PEN_BRUSH,-1);
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry view-Menu
+ pViewMenu = new QPopupMenu(this);
+ pViewMenu.setCheckable(true);
+ pViewMenu.insertItem(i18n("&Toolbar"), ID_VIEW_TOOLBAR,-1);
+ pViewMenu.insertItem(i18n("&Statusbar"), ID_VIEW_STATUSBAR,-1);
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry window-Menu
+ pWindowMenu = new QPopupMenu(this);
+ pWindowMenu.setCheckable(true);
+
+
+ ///////////////////////////////////////////////////////////////////
+ // menuBar entry helpMenu
+
+ QPopupMenu pHelpMenu = helpMenu(i18n("Java KScribble " + Main.VERSION + "\n\n(c) 2002 by\n" +
+ "Ralf Nolden\nRalf.Nolden@post.rwth-aachen.de"),true);
+
+ ///////////////////////////////////////////////////////////////////
+ // MENUBAR CONFIGURATION
+ // insert your popup menus with the according menubar entries in the order
+ // they will appear later from left to right
+ menuBar().insertItem(i18n("&File"), pFileMenu);
+ menuBar().insertItem(i18n("&Edit"), pEditMenu);
+ menuBar().insertItem(i18n("&Pen"), pPenMenu);
+ menuBar().insertItem(i18n("&View"), pViewMenu);
+ menuBar().insertItem(i18n("&Window"), pWindowMenu );
+ menuBar().insertItem(i18n("&Help"), pHelpMenu);
+
+ ///////////////////////////////////////////////////////////////////
+ // CONNECT THE MENU SLOTS WITH SIGNALS
+ // for execution slots and statusbar messages
+ connect(pFileMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pFileMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ connect(pEditMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pEditMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ connect(pPenMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pPenMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ connect(pViewMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pViewMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ connect(pWindowMenu, SIGNAL("aboutToShow()" ), SLOT( "windowMenuAboutToShow()" ) );
+ connect(pWindowMenu, SIGNAL("activated(int)"), SLOT("commandCallback(int)"));
+ connect(pWindowMenu, SIGNAL("highlighted(int)"), SLOT("statusCallback(int)"));
+
+ }
+
+
+ private void initToolBar() {
+
+ ///////////////////////////////////////////////////////////////////
+ // TOOLBAR
+
+ toolBar().insertButton(KDE.BarIcon("filenew"), ID_FILE_NEW, true, i18n("New File"),-1);
+ toolBar().insertButton(KDE.BarIcon("fileopen"), ID_FILE_OPEN, true, i18n("Open File"),-1);
+ toolBar().insertButton(KDE.BarIcon("filefloppy"), ID_FILE_SAVE, true, i18n("Save File"),-1);
+ toolBar().insertButton(KDE.BarIcon("fileprint"), ID_FILE_PRINT, true, i18n("Print"),-1);
+ toolBar().insertSeparator();
+ toolBar().insertButton(KDE.BarIcon("editcut"), ID_EDIT_CUT, true, i18n("Cut"),-1);
+ toolBar().insertButton(KDE.BarIcon("editcopy"), ID_EDIT_COPY, true, i18n("Copy"),-1);
+ toolBar().insertButton(KDE.BarIcon("editpaste"), ID_EDIT_PASTE, true, i18n("Paste"),-1);
+ toolBar().insertSeparator();
+ toolBar().insertButton(KDE.BarIcon("pencolor"), ID_PEN_COLOR, true, i18n("Color"),-1 );
+ toolBar().insertButton(KDE.BarIcon("penwidth"), ID_PEN_BRUSH, true, i18n("Width"),-1 );
+ toolBar().insertSeparator();
+ toolBar().insertButton(KDE.BarIcon("help"), ID_HELP_CONTENTS, SIGNAL("clicked()"),
+ this, SLOT("appHelpActivated()"), true,i18n("Help"),-1);
+
+ QToolButton btnwhat = QWhatsThis.whatsThisButton(toolBar());
+ QToolTip.add(btnwhat, i18n("What's this...?"));
+ toolBar().insertWidget(ID_HELP_WHATS_THIS, btnwhat.sizeHint().width(), btnwhat);
+
+ ///////////////////////////////////////////////////////////////////
+ // INSERT YOUR APPLICATION SPECIFIC TOOLBARS HERE WITH toolBar(n)
+
+
+ ///////////////////////////////////////////////////////////////////
+ // CONNECT THE TOOLBAR SLOTS WITH SIGNALS - add new created toolbars by their according number
+ // connect for invoking the slot actions
+ connect(toolBar(), SIGNAL("clicked(int)"), SLOT("commandCallback(int)"));
+ // connect for the status help on holing icons pressed with the mouse button
+ connect(toolBar(), SIGNAL("pressed(int)"), SLOT("statusCallback(int)"));
+
+ }
+
+
+ /** sets up the kstatusBar for the main window by initialzing a statuslabel.
+ */
+ protected void initStatusBar() {
+ ///////////////////////////////////////////////////////////////////
+ // STATUSBAR
+ // TODO: add your own items you need for displaying current application status.
+ kstatusBar().insertItem(i18n("Ready."), ID_STATUS_MSG);
+ }
+
+ /** creates the centerwidget of the KTMainWindow instance and sets it as the view
+ */
+ protected void initView() {
+
+ ////////////////////////////////////////////////////////////////////
+ // here the main view of the KTMainWindow is created by a background box and
+ // the QWorkspace instance for MDI view.
+ QVBox view_back = new QVBox( this );
+ view_back.setFrameStyle( QFrame.StyledPanel | QFrame.Sunken );
+ pWorkspace = new QWorkspace( view_back, "" );
+ connect(pWorkspace, SIGNAL("windowActivated(QWidget)"), this, SLOT("setWndTitle(QWidget)"));
+// setView(view_back);
+ setCentralWidget(view_back);
+ }
+
+ void createClient(KScribbleDoc doc) {
+ KScribbleView w = new KScribbleView(doc, pWorkspace,null,WDestructiveClose);
+ w.installEventFilter(this);
+ doc.addView(w);
+ w.setIcon(kapp.miniIcon());
+ if ( pWorkspace.windowList().isEmpty() ) // show the very first window in maximized mode
+ w.showMaximized();
+ else
+ w.show();
+ }
+
+ void addRecentFile(String file) {
+
+
+ if(recentFiles != null && recentFiles.contains(file))
+ return; // it's already there
+
+ if( recentFiles.size() < 5)
+ recentFiles.add(0,file);
+ else{
+ recentFiles.remove(recentFiles.remove(recentFiles.size()-1));
+ recentFiles.add(0,file);
+ }
+
+ pRecentFileMenu.clear();
+
+ Iterator it = recentFiles.iterator();
+ while (it.hasNext()) {
+ pRecentFileMenu.insertItem((String)it.next());
+ }
+
+ }
+
+ /** opens a file specified by commandline option
+ */
+ public void openDocumentFile(KURL url) {
+ slotStatusMsg(i18n("Opening file..."));
+
+ KScribbleDoc doc;
+ String file = url.directory(false,true) + url.fileName();
+
+ Iterator it = pDocList.iterator();
+
+ while (it.hasNext()) {
+
+ doc = (KScribbleDoc)it.next();
+ // check, if document already open. If yes, set the focus to the first view
+ if(doc.pathName().equals(file)) {
+
+ KScribbleView view=doc.firstView();
+ view.setFocus();
+ return;
+ }
+ }
+ doc = new KScribbleDoc();
+ pDocList.add(doc);
+ doc.newDocument();
+ // Creates an untitled window if file is 0
+ if(file == null || file.length() == 0) {
+ untitledCount+=1;
+ String fileName= i18n("Untitled" +untitledCount);
+ doc.setPathName(fileName);
+ doc.setTitle(fileName);
+ }
+ // Open the file
+ else {
+
+ String format= QImageIO.imageFormat(file);
+ if(!doc.openDocument(file,format))
+ KMessageBox.error (this,i18n("Could not open document !"), i18n("Error !"),KMessageBox.Notify);
+ addRecentFile(file);
+ }
+ // create the window
+ createClient(doc);
+ slotStatusMsg(i18n("Ready."));
+
+ }
+
+
+ public void openDocumentFile() {
+ openDocumentFile(new KURL());
+ return;
+ }
+
+ void windowMenuAboutToShow() {
+ pWindowMenu.clear();
+
+ pWindowMenu.insertItem(i18n("&New Window"), ID_WINDOW_NEW_WINDOW);
+ pWindowMenu.insertItem(i18n("&Cascade"),
+ pWorkspace, SLOT("cascade()" ),new QKeySequence(0) , ID_WINDOW_CASCADE );
+ pWindowMenu.insertItem(i18n("&Tile"),
+ pWorkspace, SLOT("tile()" ),new QKeySequence(0) , ID_WINDOW_TILE );
+
+ if ( pWorkspace.windowList().isEmpty() ) {
+
+ disableCommand(ID_WINDOW_NEW_WINDOW);
+ disableCommand(ID_WINDOW_CASCADE);
+ disableCommand(ID_WINDOW_TILE);
+ }
+
+ pWindowMenu.insertSeparator();
+
+ ArrayList windows = pWorkspace.windowList();
+
+ for ( int i = 0; i < windows.size(); ++i ) {
+ int id = pWindowMenu.insertItem((i+1)+ ((QWidget)windows.get(i)).caption(),
+ this, SLOT( "windowMenuActivated( int )" ) );
+ pWindowMenu.setItemParameter( id, i );
+ pWindowMenu.setItemChecked( id, pWorkspace.activeWindow() == (QWidget)windows.get(i) );
+ }
+ }
+
+ void windowMenuActivated( int id ) {
+ QWidget w = (QWidget)pWorkspace.windowList().get( id );
+ if ( w != null )
+ w.setFocus();
+ }
+
+ void setWndTitle(QWidget qw){
+ setCaption(pWorkspace.activeWindow() != null ? pWorkspace.activeWindow().caption() : "");
+ }
+
+ void enableCommand(int id_) {
+ ///////////////////////////////////////////////////////////////////
+ // enable menu and toolbar functions by their ID's
+ menuBar().setItemEnabled(id_, true);
+ toolBar().setItemEnabled(id_, true);
+ }
+
+ void disableCommand(int id_) {
+ ///////////////////////////////////////////////////////////////////
+ // disable menu and toolbar functions by their ID's
+ menuBar().setItemEnabled(id_, false);
+ toolBar().setItemEnabled(id_, false);
+ }
+
+ void commandCallback(int id_) {
+ switch (id_) {
+ case ID_FILE_NEW:
+ slotFileNew();
+ break;
+
+ case ID_FILE_OPEN:
+ slotFileOpen();
+ break;
+
+ case ID_FILE_SAVE:
+ slotFileSave();
+ break;
+
+ case ID_FILE_SAVE_AS:
+ slotFileSaveAs();
+ break;
+
+ case ID_FILE_CLOSE:
+ slotFileClose();
+ break;
+
+ case ID_FILE_PRINT:
+ slotFilePrint();
+ break;
+
+ case ID_FILE_QUIT:
+ slotFileQuit();
+ break;
+
+ case ID_EDIT_CUT:
+ slotEditCut();
+ break;
+
+ case ID_EDIT_COPY:
+ slotEditCopy();
+ break;
+
+ case ID_EDIT_PASTE:
+ slotEditPaste();
+ break;
+
+ case ID_EDIT_CLEAR_ALL:
+ slotEditClearAll();
+ break;
+
+ case ID_PEN_BRUSH:
+ slotPenBrush();
+ break;
+
+ case ID_PEN_COLOR:
+ slotPenColor();
+ break;
+
+ case ID_VIEW_TOOLBAR:
+ slotViewToolBar();
+ break;
+
+ case ID_VIEW_STATUSBAR:
+ slotViewStatusBar();
+ break;
+
+ case ID_WINDOW_NEW_WINDOW:
+ slotWindowNewWindow();
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ void statusCallback(int id_) {
+ switch (id_) {
+ case ID_FILE_NEW:
+ slotStatusHelpMsg(i18n("Creates a new document"));
+ break;
+
+ case ID_FILE_OPEN:
+ slotStatusHelpMsg(i18n("Opens an existing document"));
+ break;
+
+ case ID_FILE_OPEN_RECENT:
+ slotStatusHelpMsg(i18n("Opens a recently used file"));
+ break;
+
+ case ID_FILE_SAVE:
+ slotStatusHelpMsg(i18n("Saves the currently active document"));
+ break;
+
+ case ID_FILE_SAVE_AS:
+ slotStatusHelpMsg(i18n("Saves the currently active document as under a new filename"));
+ break;
+
+ case ID_FILE_CLOSE:
+ slotStatusHelpMsg(i18n("Closes the currently active document"));
+ break;
+
+ case ID_FILE_PRINT:
+ slotStatusHelpMsg(i18n("Prints out the actual document"));
+ break;
+
+ case ID_FILE_QUIT:
+ slotStatusHelpMsg(i18n("Quits the application"));
+ break;
+
+ case ID_EDIT_UNDO:
+ slotStatusHelpMsg(i18n("Reverts the last editing action"));
+ break;
+
+ case ID_EDIT_CUT:
+ slotStatusHelpMsg(i18n("Cuts the selected section and puts it to the clipboard"));
+ break;
+
+ case ID_EDIT_COPY:
+ slotStatusHelpMsg(i18n("Copies the selected section to the clipboard"));
+ break;
+
+ case ID_EDIT_PASTE:
+ slotStatusHelpMsg(i18n("Pastes the clipboard contents to actual position"));
+ break;
+
+ case ID_EDIT_CLEAR_ALL:
+ slotStatusHelpMsg(i18n("Clears the document contents"));
+ break;
+
+ case ID_PEN_BRUSH:
+ slotStatusHelpMsg(i18n("Sets the pen width"));
+ break;
+
+ case ID_PEN_COLOR:
+ slotStatusHelpMsg(i18n("Sets the current pen color"));
+ break;
+
+ case ID_VIEW_TOOLBAR:
+ slotStatusHelpMsg(i18n("Enables/disables the toolbar"));
+ break;
+
+ case ID_VIEW_STATUSBAR:
+ slotStatusHelpMsg(i18n("Enables/disables the statusbar"));
+ break;
+
+ case ID_WINDOW_NEW_WINDOW:
+ slotStatusHelpMsg(i18n("Opens a new view for the current document"));
+ break;
+
+ case ID_WINDOW_CASCADE:
+ slotStatusHelpMsg(i18n("Cascades all windows"));
+ break;
+
+ case ID_WINDOW_TILE:
+ slotStatusHelpMsg(i18n("Tiles all windows"));
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ void slotStatusHelpMsg(String text) {
+ ///////////////////////////////////////////////////////////////////
+ // change status message of whole statusbar temporary (text, msec)
+ statusBar().message(text, 2000);
+ }
+
+
+ /** returns a pointer to the current document connected to the KTMainWindow instance and is used by
+ * the View class to access the document object's methods
+ */
+ public KScribbleDoc getDocument() {
+ return doc;
+ }
+
+ /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration
+ * file
+ */
+ protected void saveOptions() {
+ config.setGroup("General Options");
+ config.writeEntry("Geometry", size());
+ config.writeEntry("Show Toolbar", toolBar().isVisible());
+ config.writeEntry("Show Statusbar",statusBar().isVisible());
+ config.writeEntry("ToolBarPos", (int) toolBar().barPos());
+ String[] rf = new String[recentFiles.size()];
+ rf = (String[]) recentFiles.toArray(rf);
+ if (rf != null)
+ config.writeEntry("Recent Files", rf);
+ }
+
+
+
+ /** read general Options again and initialize all variables like the recent file list
+ */
+ private void readOptions() {
+
+ config.setGroup("General Options");
+
+ // bar status settings
+ boolean bViewToolbar = config.readBoolEntry("Show Toolbar", true);
+ menuBar().setItemChecked(ID_VIEW_TOOLBAR, bViewToolbar);
+ if(!bViewToolbar) {
+ toolBar("mainToolBar").hide();
+ }
+
+ boolean bViewStatusbar = config.readBoolEntry("Show Statusbar", true);
+ menuBar().setItemChecked(ID_VIEW_STATUSBAR, bViewStatusbar);
+ if(!bViewStatusbar) {
+ toolBar("mainToolBar").hide();
+ }
+
+ // bar position settings
+ int toolBarPos = KToolBar.Top;
+ toolBarPos = config.readUnsignedNumEntry("ToolBarPos", KToolBar.Top);
+ toolBar().setBarPos(toolBarPos);
+
+ // initialize the recent file list
+ // commented out until fix is applied.
+ recentFiles = config.readListEntry("Recent Files");
+ Iterator it = recentFiles.iterator();
+ while (it.hasNext()) {
+ pRecentFileMenu.insertItem((String) it.next());
+ }
+
+ // Read the size information and resize from settings.
+ QSize size = new QSize();
+ config.readSizeEntry("Geometry",size);
+ if(!size.isEmpty()) {
+ resize(size);
+ }
+ else
+ resize(400,350);
+
+ }
+
+ /** saves the window properties for each open window during session end to the session config file, including saving the currently
+ * opened file by a temporary filename provided by KApplication.
+ * @see KTMainWindow#saveProperties
+ */
+ protected void saveProperties(KConfig _cfg) {
+
+ }
+
+
+ /** reads the session config file and restores the application's state including the last opened files and documents by reading the
+ * temporary files saved by saveProperties()
+ * @see KTMainWindow#readProperties
+ */
+ protected void readProperties(KConfig _cfg) {
+ }
+
+ /** queryClose is called by KTMainWindow on each closeEvent of a window. Against the
+ * default implementation (only returns true), this calles saveModified() on the document object to ask if the document shall
+ * be saved if Modified; on cancel the closeEvent is rejected.
+ * @see KTMainWindow#queryClose
+ * @see KTMainWindow#closeEvent
+ */
+ protected boolean queryClose() {
+
+ ArrayList saveFiles = new ArrayList();
+ KScribbleDoc doc;
+
+ if(pDocList.isEmpty())
+ return true;
+
+ Iterator it = pDocList.iterator();
+
+ while (it.hasNext()) {
+ doc = (KScribbleDoc)it.next();
+ if(doc.isModified())
+ saveFiles.add(doc.title());
+
+ }
+
+ if(saveFiles.isEmpty())
+ return true;
+
+ // lets load up a String array with the documents to save.
+ String[] sf = new String[saveFiles.size()];
+ for (int x = 0; x < saveFiles.size(); x++) {
+ sf[x] = (String)saveFiles.get(x);
+ }
+ switch (KMessageBox.questionYesNoList(this,
+ i18n("One or more documents have been modified.\nSave changes before exiting?"),sf))
+ {
+ case KMessageBox.Yes:
+
+ Iterator itr = pDocList.iterator();
+
+ while (itr.hasNext()) {
+ doc = (KScribbleDoc)itr.next();
+ if(doc.title().indexOf(i18n("Untitled")) > 0) {
+
+ slotFileSaveAs();
+ }
+ else {
+ if(!doc.saveDocument(doc.pathName())){
+ KMessageBox.error (this,i18n("Could not save the current document !"), i18n("I/O Error !"),KMessageBox.Notify);
+ return false;
+ }
+
+ }
+
+
+ }
+ return true;
+ case KMessageBox.No:
+ default:
+ return true;
+ }
+
+ }
+
+ /** queryExit is called by KTMainWindow when the last window of the application is going to be closed during the closeEvent().
+ * Against the default implementation that just returns true, this calls saveOptions() to save the settings of the last window's
+ * properties.
+ * @see KTMainWindow#queryExit
+ * @see KTMainWindow#closeEvent
+ */
+ protected boolean queryExit() {
+ saveOptions();
+ return true;
+ }
+
+/////////////////////////////////////////////////////////////////////
+// SLOT IMPLEMENTATION
+/////////////////////////////////////////////////////////////////////
+
+
+ void slotFileNew() {
+ slotStatusMsg(i18n("Creating new document..."));
+
+ openDocumentFile();
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileOpen() {
+ slotStatusMsg(i18n("Opening file..."));
+
+ String fileToOpen=KFileDialog.getOpenFileName(QDir.currentDirPath(),
+ KImageIO.pattern(KImageIO.Reading), this, i18n("Open File..."));
+ if(fileToOpen != null && fileToOpen.length() > 0) {
+ openDocumentFile(new KURL(fileToOpen));
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+
+ void slotFileSave() {
+ slotStatusMsg(i18n("Saving file..."));
+ KScribbleView m = (KScribbleView)pWorkspace.activeWindow();
+ if( m != null) {
+ KScribbleDoc doc = m.getDocument();
+ if(doc.title().indexOf(i18n("Untitled")) > 0)
+ slotFileSaveAs();
+ else
+ if(!doc.saveDocument(doc.pathName()))
+ KMessageBox.error (this,i18n("Could not save the current document !"), i18n("I/O Error !"),KMessageBox.Notify); }
+
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileSaveAs() {
+ slotStatusMsg(i18n("Saving file with a new filename..."));
+
+ String newName=KFileDialog.getSaveFileName(QDir.currentDirPath(),
+ KImageIO.pattern(KImageIO.Writing), this, i18n("Save as..."));
+
+ if(newName != null) {
+ KScribbleView m = (KScribbleView)pWorkspace.activeWindow();
+ if( m != null ) {
+ KScribbleDoc doc = m.getDocument();
+
+ String format=new QFileInfo(newName).extension();
+ format=format.toUpperCase();
+
+ if(!doc.saveDocument(newName,format)) {
+ KMessageBox.error (this,i18n("Could not save the current document !"), i18n("I/O Error !"),KMessageBox.Notify);
+ return;
+ }
+ doc.changedViewList();
+ setWndTitle(m);
+ }
+
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileClose() {
+ slotStatusMsg(i18n("Closing file..."));
+
+ KScribbleView m = (KScribbleView)pWorkspace.activeWindow();
+ if( m != null ) {
+ KScribbleDoc doc=m.getDocument();
+ doc.closeDocument();
+ }
+
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFilePrint() {
+ slotStatusMsg(i18n("Printing..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null)
+ m.print( printer );
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileQuit() {
+ slotStatusMsg(i18n("Exiting..."));
+ saveOptions();
+ // close the first window, the list makes the next one the first again.
+ // This ensures that queryClose() is called on each window to ask for closing
+ KMainWindow w;
+
+ ArrayList memberlist = memberList();
+ if(memberlist != null) {
+ Iterator it = memberlist.iterator();
+ while (it.hasNext()) {
+ w = (KMainWindow)it.next();
+ // only close the window if the closeEvent is accepted. If the user
+ // presses Cancel on the saveModified() dialog,
+ // the window and the application stay open.
+ if(!w.close())
+ break;
+ }
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotFileOpenRecent(int id_) {
+ slotStatusMsg(i18n("Opening file..."));
+
+ KURL kurl = new KURL(pRecentFileMenu.text(id_));
+// openDocumentFile(pRecentFileMenu.text(id_));
+ openDocumentFile(kurl);
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotEditClearAll() {
+ slotStatusMsg(i18n("Clearing the document contents..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null ){
+ KScribbleDoc pDoc = m.getDocument();
+ pDoc.editClearAll();
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotPenBrush() {
+ slotStatusMsg(i18n("Setting brush width..."));
+
+ // get one window with document for a current pen width
+ ArrayList windows = pWorkspace.windowList();
+ KScribbleView m = (KScribbleView)windows.get(0);
+ KScribbleDoc pDoc = m.getDocument();
+ int curr_width=pDoc.penWidth();
+
+ // create the dialog, get the new width and set the pen width for all documents
+ KPenBrushDlg dlg= new KPenBrushDlg(curr_width,this,"");
+ if(dlg.exec() > 0){
+ int width=dlg.getPenWidth();
+ for ( int i = 0; i < windows.size(); ++i ) {
+ m = (KScribbleView)windows.get(i);
+ if ( m != null ) {
+ pDoc = m.getDocument();
+ pDoc.setPenWidth(width);
+ }
+ }
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotPenColor() {
+ slotStatusMsg(i18n("Selecting pen color..."));
+
+ QColor myColor = new QColor();
+ int result = KColorDialog.getColor( myColor, this );
+ if ( result == KColorDialog.Accepted )
+ {
+ ArrayList windows = pWorkspace.windowList();
+ KScribbleDoc pDoc;
+ KScribbleView m;
+ for ( int i = 0; i < windows.size(); ++i ) {
+ m = (KScribbleView)windows.get(i);
+ if ( m != null) {
+ pDoc = m.getDocument();
+ pDoc.setPenColor(myColor);
+ }
+ }
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotEditUndo() {
+ slotStatusMsg(i18n("Reverting last action..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+// if ( m != null )
+// m.undo();
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** put the marked object into the clipboard and remove
+ * it from the document
+ */
+ void slotEditCut() {
+ slotStatusMsg(i18n("Cutting selection..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null )
+ m.cutSelection();
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** put the marked text/object into the clipboard
+ */
+ public void slotEditCopy() {
+ slotStatusMsg(i18n("Copying selection to clipboard..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null)
+ m.copySelection();
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** paste the clipboard into the document
+ */
+ public void slotEditPaste() {
+ slotStatusMsg(i18n("Inserting clipboard contents..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null ) {
+ m.pasteSelection();
+ }
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** toggles the toolbar
+ */
+
+ void slotViewToolBar() {
+ slotStatusMsg(i18n("Toggle the toolbar..."));
+ ///////////////////////////////////////////////////////////////////
+ // turn Toolbar on or off
+ if( menuBar().isItemChecked(ID_VIEW_TOOLBAR)) {
+ menuBar().setItemChecked(ID_VIEW_TOOLBAR, false);
+ toolBar("mainToolBar").hide();
+
+ }
+ else {
+ menuBar().setItemChecked(ID_VIEW_TOOLBAR, true);
+ toolBar("mainToolBar").show();
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** toggles the statusbar
+ */
+ void slotViewStatusBar() {
+ slotStatusMsg(i18n("Toggle the statusbar..."));
+ ///////////////////////////////////////////////////////////////////
+ //turn Statusbar on or off
+ if( menuBar().isItemChecked(ID_VIEW_STATUSBAR)) {
+ menuBar().setItemChecked(ID_VIEW_STATUSBAR, false);
+ kstatusBar().hide();
+
+ }
+ else {
+ menuBar().setItemChecked(ID_VIEW_STATUSBAR, true);
+ kstatusBar().show();
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ void slotWindowNewWindow() {
+ slotStatusMsg(i18n("Opening a new application window..."));
+
+ KScribbleView m = (KScribbleView) pWorkspace.activeWindow();
+ if ( m != null ){
+ KScribbleDoc doc = m.getDocument();
+ createClient(doc);
+ }
+
+ slotStatusMsg(i18n("Ready."));
+ }
+
+ /** changes the statusbar contents for the standard label permanently, used to indicate current actions.
+ * @param text the text that is displayed in the statusbar
+ */
+ public void slotStatusMsg(String text) {
+ ///////////////////////////////////////////////////////////////////
+ // change status message permanently
+ kstatusBar().clear();
+ kstatusBar().changeItem(text, ID_STATUS_MSG);
+ }
+
+ /** accepts drops and opens a new document
+ for each drop */
+ protected void dropEvent( QDropEvent e){
+ QImage img = new QImage();
+ if ( QImageDrag.decode(e, img) ) {
+ KScribbleDoc doc = new KScribbleDoc();
+ untitledCount+=1;
+ String fileName= i18n("Untitled") + untitledCount;
+ doc.setPathName(fileName);
+ doc.setTitle(fileName);
+ doc.newDocument();
+ pDocList.add(doc);
+ KPixmap tmp = new KPixmap();
+ tmp.resize(img.size());
+ tmp.convertFromImage(img);
+ doc.setPixmap(tmp);
+ doc.resizeDocument(tmp.size());
+ doc.setModified();
+ createClient(doc);
+ }
+ }
+ /** accepts drag events for images */
+ protected void dragEnterEvent( QDragEnterEvent e){
+ e.accept(QImageDrag.canDecode(e));
+ }
+
+
+}
diff --git a/kdejava/koala/examples/kscribble/KScribbleDoc.java b/kdejava/koala/examples/kscribble/KScribbleDoc.java
new file mode 100644
index 00000000..d51af4e1
--- /dev/null
+++ b/kdejava/koala/examples/kscribble/KScribbleDoc.java
@@ -0,0 +1,300 @@
+import java.util.*;
+
+import org.kde.qt.*;
+import org.kde.koala.*;
+
+/** KScribbleDoc provides a document object for a document-view model.
+ *
+ * The KScribbleDoc class provides a document object that can be used in conjunction with the classes JavaApiTestApp and KScribbleView
+ * to create a document-view model for standard KDE applications based on KApplication and KMainWindow. Thereby, the document object
+ * is created by the JavaApiTestApp instance and contains the document structure with the according methods for manipulation of the document
+ * data by KScribbleView objects. Also, KScribbleDoc contains the methods for serialization of the document data from and to files.
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 1.2 code generation
+ */
+public class KScribbleDoc extends QObject {
+
+ /** the list of the views currently connected to the document */
+ private ArrayList pViewList;
+ private String m_title;
+ private String m_filename;
+ private QSize size;
+ private QPen pen;
+ public QPointArray polyline;
+ public KPixmap buffer;
+
+ /** the modified flag of the current document */
+ private boolean modified;
+ private KURL doc_url;
+
+
+ public KScribbleDoc() {
+
+ pViewList = new ArrayList();
+ }
+
+ void addView(KScribbleView view) {
+ pViewList.add(view);
+ changedViewList();
+ }
+
+ void removeView(KScribbleView view) {
+ pViewList.remove(view);
+ if(!pViewList.isEmpty())
+ changedViewList();
+ else
+ deleteContents();
+ }
+
+ void changedViewList(){
+
+ KScribbleView w;
+ if(pViewList.size() == 1){
+ w=(KScribbleView)pViewList.get(0);
+ w.setCaption(m_title);
+ }
+ else{
+ int i = 1;
+ Iterator it = pViewList.iterator();
+ while(it.hasNext()) {
+ w = (KScribbleView)it.next();
+ w.setCaption(m_title + ":"+ i++);
+
+ }
+ }
+ }
+
+ boolean isLastView() {
+ return (pViewList.size() == 1);
+ }
+
+
+ void updateAllViews(KScribbleView sender) {
+ KScribbleView w;
+ Iterator it = pViewList.iterator();
+ while(it.hasNext()) {
+ w = (KScribbleView)it.next();
+ w.update(sender);
+
+ }
+
+ }
+
+ void setPathName(String name) {
+ m_filename=name;
+ m_title= new QFileInfo(name).fileName();
+ }
+
+ String pathName() {
+ return m_filename;
+ }
+
+ /** returns the current pen in use */
+ QPen currentPen() {
+ return pen;
+ }
+
+ /** returns the pen color */
+ int penWidth() {
+ return pen.width();
+ }
+
+ /** returns the pen color */
+ QColor penColor(){
+ return pen.color();
+ }
+
+ /** sets the pen width */
+ void setPenWidth( int w ){
+ pen.setWidth( w );
+ }
+
+ /** sets the pen color */
+ void setPenColor( QColor c ){
+ pen.setColor( c );
+ }
+
+ /** sets the pen style by a second toolbar */
+// void setPenStyle( PenStyle s) {
+// pen.setStyle(s);
+// }
+
+ void setTitle(String title) {
+
+ m_title=title;
+ }
+
+ String title() {
+ return m_title;
+ }
+
+ /** sets the pixmap contents. Used by KScribbleApp
+ to create a new document by drop events */
+ void setPixmap(KPixmap pix) {
+ buffer=pix;
+ };
+ void resizeDocument(QSize m_size) {
+ size=m_size;
+ };
+
+ void closeDocument() {
+ KScribbleView w;
+ if(!isLastView()) {
+ Iterator it = pViewList.iterator();
+ while(it.hasNext()) {
+ w = (KScribbleView)it.next();
+ if (!w.close())
+ break;
+
+ }
+
+ }
+ if(isLastView()) {
+ w= (KScribbleView)pViewList.get(0);
+ w.close();
+ }
+ }
+
+ boolean newDocument() {
+ /////////////////////////////////////////////////
+ // TODO: Add your document initialization code here
+ size=new QSize(300,200 );
+ pen= new QPen();
+ pen.setColor(Qt.black());
+ pen.setWidth(3);
+ polyline= new QPointArray(3);
+ if (buffer == null) {
+ buffer = new KPixmap();
+ }
+ buffer.resize(size);
+ buffer.fill( Qt.white() );
+ /////////////////////////////////////////////////
+ modified=false;
+ return true;
+ }
+
+ public boolean openDocument(String filename, String format) {
+
+ QFile f = new QFile( filename );
+ // if ( !f.open( IO_ReadOnly ) )
+ // return false;
+ /////////////////////////////////////////////////
+ // TODO: Add your document opening code here
+ if(!buffer.load( filename, format, 0))
+ return false;
+ size=buffer.size();
+ /////////////////////////////////////////////////
+ // f.close();
+
+ modified=false;
+ m_filename=filename;
+ m_title=new QFileInfo(f).fileName();
+ return true;
+ }
+
+ boolean saveDocument(String filename) {
+ return saveDocument(filename,"") ;
+ }
+
+ /** returns the first view instance */
+ KScribbleView firstView(){
+ return (KScribbleView) pViewList.get(0);
+ };
+
+ boolean saveDocument(String filename, String format /*=0*/) {
+ QFile f = new QFile( filename );
+ // if ( !f.open( IO_WriteOnly ) )
+ // return false;
+
+ /////////////////////////////////////////////////
+ // TODO: Add your document saving code here
+ if(!buffer.save( filename, format ))
+ return false;
+ /////////////////////////////////////////////////
+
+ // f.close();
+
+ modified=false;
+ m_filename=filename;
+ m_title=new QFileInfo(f).fileName();
+ return true;
+ }
+
+ void deleteContents() {
+ /////////////////////////////////////////////////
+ // TODO: Add implementation to delete the document contents
+ buffer.fill( Qt.white() );
+ /////////////////////////////////////////////////
+
+ }
+
+ boolean isModified() {
+ return modified;
+ }
+
+ void setModified() {
+ modified = true;
+ }
+
+ boolean canCloseFrame(KScribbleView pFrame) {
+ if(!isLastView())
+ return true;
+
+ boolean ret=false;
+ if(isModified()) {
+ String saveName = new String();
+ switch(KMessageBox.warningYesNoCancel(pFrame, i18n("The current file has been modified.\n" +
+ "Do you want to save it?"),title()))
+ {
+ case KMessageBox.Yes:
+ if(title().indexOf(i18n("Untitled")) > 0) {
+ saveName= KFileDialog.getSaveFileName(QDir.currentDirPath(),
+ i18n("*|All files"), pFrame, i18n("Save as..."));
+ if(saveName == null || saveName.length() == 0)
+ return false;
+ }
+ else
+ saveName=pathName();
+
+ if(!saveDocument(saveName)) {
+ switch(KMessageBox.warningYesNo(pFrame,i18n("Could not save the current document !\n" +
+ "Close anyway ?"), i18n("I/O Error !")))
+ {
+ case KMessageBox.Yes:
+ ret=true;
+ case KMessageBox.No:
+ ret=false;
+ }
+ }
+ else
+ ret=true;
+ break;
+ case KMessageBox.No:
+ ret=true;
+ break;
+ case KMessageBox.Cancel:
+ default:
+ ret=false;
+ break;
+ }
+ }
+ else
+ ret=true;
+
+ return ret;
+ }
+
+ /** get the document size */
+ QSize docSize() {
+ return size;
+ }
+
+ void editClearAll() {
+ deleteContents();
+ setModified();
+ updateAllViews(null);
+
+ }
+
+}
diff --git a/kdejava/koala/examples/kscribble/KScribbleView.java b/kdejava/koala/examples/kscribble/KScribbleView.java
new file mode 100644
index 00000000..464227ec
--- /dev/null
+++ b/kdejava/koala/examples/kscribble/KScribbleView.java
@@ -0,0 +1,342 @@
+import org.kde.qt.*;
+import org.kde.koala.*;
+
+/** The KScribbleView class provides the view widget for the KScribble instance.
+ * The View instance inherits QWidget as a base class and represents the view object of a KMainWindow. As KScribbleView is part of the
+ * docuement-view model, it needs a reference to the document object connected with it by the KScribble class to manipulate and display
+ * the document structure provided by the KScribbleDoc class.
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 0.4 code generation
+ */
+public class KScribbleView extends QScrollView {
+
+ private QClipboard cb;
+ private KScribbleDoc doc;
+ private static final int IDLE = 0;
+ private static final int DRAW = 1;
+ private static final int SELECT = 2;
+ private static final int PASTE = 3;
+ private static final int DRAG = 4;
+
+ private QPixmap tmp = new QPixmap();
+
+ private int action = IDLE;
+ private QRect select = new QRect();
+
+ private KIconLoader k = new KIconLoader();
+ private QImageDrag qid;
+
+ public KScribbleView(KScribbleDoc pDoc, QWidget parent, String name, int wflags) {
+ super(parent, name,wflags | WPaintClever | WNorthWestGravity | WRepaintNoErase);
+ setBackgroundMode(PaletteBase);
+ cb = QApplication.clipboard();
+ viewport().setAcceptDrops(true);
+ setDragAutoScroll(true);
+ doc=pDoc;
+ action=IDLE;
+ viewport().setCursor( Qt.crossCursor() );
+
+ QSize size=doc.docSize();
+ resizeContents(size.width(), size.height());
+ resize(size);
+
+ }
+
+ void update(KScribbleView pSender){
+ if(pSender != this)
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+ public KScribbleDoc getDocument() {
+ return doc;
+ }
+
+ protected void keyPressEvent( QKeyEvent e ) {
+ switch (e.key()) {
+ case Key_Right:
+ scrollBy( 10, 0 );
+ break;
+ case Key_Left:
+ scrollBy( -10,0);
+ break;
+ case Key_Up:
+ scrollBy( 0, -10 );
+ break;
+ case Key_Down:
+ scrollBy( 0, 10 );
+ break;
+ case Key_Home:
+ setContentsPos(0,0);
+ break;
+ case Key_End:
+ setContentsPos(0,viewport().height()-viewport().height());
+ break;
+ case Key_PageUp:
+ scrollBy( 0, -viewport().height() );
+ break;
+ case Key_PageDown:
+ scrollBy( 0, viewport().height() );
+ break;
+ }
+
+ }
+
+ /** cuts out a selection */
+ void cutSelection() {
+ select=select.normalize();
+ QPixmap cb_pix = new QPixmap();
+ cb_pix.resize(select.size());
+ // copy selection to cb_pix and copy to clipboard
+ bitBlt(cb_pix,0, 0, doc.buffer, select.x()+contentsX(), select.y()+contentsY(), cb_pix.width(),cb_pix.height());
+ cb.setPixmap(cb_pix);
+ // fill cb_pix with white and copy to selection area
+ cb_pix.fill(Qt.white());
+ bitBlt(doc.buffer, select.x()+contentsX(), select.y()+contentsY(),cb_pix, 0, 0, cb_pix.width(), cb_pix.height());
+ action = IDLE;
+ doc.setModified();
+ doc.updateAllViews(this);
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+ /** pastes the clipboard contents to a selection that can be inserted into the picture */
+ void pasteSelection(){
+ select=cb.pixmap().rect();
+ action = PASTE;
+ viewport().setCursor( Qt.sizeAllCursor() );
+ }
+
+ /** copies a selection to the clipboard */
+ void copySelection(){
+ select=select.normalize();
+ QPixmap cb_pix = new QPixmap();
+ cb_pix.resize(select.size());
+ // copy selection to cb_pix and copy to clipboard
+ bitBlt(cb_pix, 0, 0,doc.buffer, select.x()+contentsX(), select.y()+contentsY(), cb_pix.width(),cb_pix.height());
+ cb.setPixmap(cb_pix);
+ action = IDLE;
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+ public void print(QPrinter pPrinter) {
+ if (pPrinter.setup(this)) {
+ QPainter p = new QPainter();
+ p.begin(pPrinter);
+
+ ///////////////////////////////
+ // TODO: add your printing code here
+ p.drawPixmap(0,0,doc.buffer);
+ ///////////////////////////////
+ p.end();
+ }
+ }
+
+ protected void viewportMousePressEvent( QMouseEvent e ) {
+ if ( e.button() == LeftButton && action == IDLE) {
+ action=DRAW;
+ doc.polyline.setPoint(0,viewportToContents(e.pos()));
+ doc.polyline.setPoint(1,viewportToContents(e.pos()));
+ doc.polyline.setPoint(2,viewportToContents(e.pos()));
+ doc.updateAllViews(this);
+ }
+ else if ( e.button() == RightButton && action == IDLE) {
+ action = SELECT;
+ QPoint pt=e.pos();
+ int x = pt.x() > contentsWidth() ? contentsWidth() : pt.x();
+ int y = pt.y() > contentsHeight() ? contentsHeight() : pt.y();
+ select.setLeft(x-1);
+ select.setTop(y-1);
+ select.setRight(x-1);
+ select.setBottom(y-1);
+ }
+ else if( action == SELECT ) {
+ action = IDLE;
+
+ select=select.normalize();
+ // drag
+ if(select.contains(e.pos(), true)) { // point inside the selection
+ tmp.resize(select.size());
+ bitBlt(tmp, 0, 0, doc.buffer, select.x()+contentsX(), select.y()+contentsY(), tmp.width(),tmp.height());
+ QImage img =tmp.convertToImage();
+ QDragObject d = new QImageDrag( img, viewport(), "" );
+ d.setPixmap(KDE.BarIcon("filenew"));
+ d.drag();
+ }
+ // remove selection
+ else
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+ else if( action == PASTE ) {
+ if ( e.button() == RightButton ) {
+ action = IDLE;
+ viewport().setCursor( Qt.crossCursor() );
+ }
+ QPoint mv_pt = new QPoint(viewport().height(), viewport().width());
+ if(new QRect(0,0,mv_pt.x(),mv_pt.y()).contains(e.pos()))
+ select.moveCenter(e.pos());
+ else {
+ select.moveBottomRight(mv_pt);
+ }
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+ }
+
+ protected void viewportMouseReleaseEvent( QMouseEvent e ) {
+ if ( action == DRAW ) {
+ action = IDLE;
+ doc.updateAllViews(this);
+ }
+ if ( action == SELECT) {
+ QPoint pt=e.pos();
+ int x = pt.x() > 0 ? pt.x() : 0;
+ int y = pt.y() > 0 ? pt.y() : 0;
+ select.setRight(x);
+ select.setBottom(y);
+ QSize size=doc.docSize();
+ select = select.intersect(new QRect(0,0,size.width(), size.height()));
+ }
+ }
+
+ /** On paste actions inserts the pasted clipboard contents
+ */
+ protected void viewportMouseDoubleClickEvent(QMouseEvent e) {
+ if( action == PASTE ) {
+ action = IDLE;
+ select.moveCenter(e.pos());
+ viewport().setCursor( Qt.crossCursor() );
+ QPixmap cb_pix = new QPixmap();
+ cb_pix.resize(cb.pixmap().size());
+ cb_pix=cb.pixmap();
+ bitBlt( doc.buffer,contentsX()+select.x(), contentsY()+select.y(),cb_pix, 0, 0, select.width(), select.height());
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ doc.setModified();
+ doc.updateAllViews(this);
+ }
+
+ }
+
+ protected void viewportMouseMoveEvent( QMouseEvent e ) {
+ if ( action == DRAW ) {
+ QPainter painter = new QPainter();
+ painter.begin( doc.buffer );
+ painter.setPen( doc.currentPen() );
+ doc.polyline.setPoint(2, doc.polyline.at(1));
+ doc.polyline.setPoint(1, doc.polyline.at(0));
+ doc.polyline.setPoint(0, viewportToContents(e.pos()));
+ painter.drawPolyline( doc.polyline );
+ painter.end();
+
+ QRect r = doc.polyline.boundingRect();
+ r = r.normalize();
+ r.setLeft( r.left() - doc.penWidth() );
+ r.setTop( r.top() - doc.penWidth() );
+ r.setRight( r.right() + doc.penWidth() );
+ r.setBottom( r.bottom() + doc.penWidth() );
+
+ bitBlt(viewport(), r.x()-contentsX(), r.y()-contentsY(), doc.buffer, r.x(), r.y(), r.width(),r.height());
+ doc.setModified();
+ doc.updateAllViews(this);
+ }
+ if ( action == SELECT ) {
+ QPoint pt=e.pos();
+ select.setWidth(select.x()+pt.x());
+ select.setHeight(select.y()+pt.y());
+ select.setRight(pt.x());
+ select.setBottom(pt.y());
+ QSize size=doc.docSize();
+ select = select.intersect(new QRect(0,0,size.width(), size.height()));
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+ if( action == PASTE ) {
+ QPoint mv_pt = new QPoint(viewport().height(), viewport().width());
+ if(new QRect(0,0,mv_pt.x(),mv_pt.y()).contains(e.pos()))
+ select.moveCenter(e.pos());
+ else {
+ select.moveBottomRight(mv_pt);
+ }
+ QRect pm_rect=cb.pixmap().rect();
+ select.setWidth(pm_rect.width());
+ select.setHeight(pm_rect.height());
+ QSize size=doc.docSize();
+ select = select.intersect(new QRect(0,0,size.width(), size.height()));
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ doc.setModified();
+ doc.updateAllViews(this);
+ }
+ }
+
+ //void KScribbleView::viewportResizeEvent( QResizeEvent *e )
+ //{
+ //}
+
+ protected void viewportPaintEvent( QPaintEvent e ) {
+ bitBlt( viewport(),0, 0, doc.buffer, contentsX(), contentsY(), doc.buffer.width(),doc.buffer.width());
+
+ if( action == PASTE )
+ {
+ tmp.resize(cb.pixmap().size());
+ tmp=cb.pixmap();
+ }
+ if( action == PASTE || action == DRAG )
+ {
+ QSize size=doc.docSize();
+ select = select.intersect(new QRect(0,0,size.width(), size.height()));
+ if(select.intersects(e.rect()))
+ bitBlt(viewport(), select.x(), select.y(), tmp, 0, 0, select.width(), select.height());
+ }
+ if( action == PASTE || action == DRAG || action == SELECT ) {
+ if(select.intersects(e.rect())) {
+ QPainter paint_area = new QPainter();
+ paint_area.begin(viewport());
+ paint_area.setPen(new QPen(Qt.black(), 0, DashLine));
+ paint_area.drawRect( select );
+ paint_area.end();
+ }
+ }
+
+ // not implemented for QScrollView yet
+// super.viewportPaintEvent(e);
+ }
+
+ protected void viewportDragEnterEvent ( QDragEnterEvent e) {
+ e.accept(QImageDrag.canDecode(e));
+ action = DRAG;
+ }
+
+ protected void viewportDragMoveEvent ( QDragMoveEvent e) {
+ QImage img = new QImage();
+
+ if ( QImageDrag.canDecode(e) ){
+ QImageDrag.decode(e, img);
+ tmp.resize(img.size());
+ tmp.convertFromImage(img);
+ select.setWidth(tmp.width());
+ select.setHeight(tmp.height());
+ select.moveCenter(e.pos());
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+ }
+
+ protected void viewportDragLeaveEvent ( QDragLeaveEvent e ) {
+ action = IDLE;
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+ protected void viewportDropEvent ( QDropEvent e) {
+ QImage img = new QImage();
+ if ( QImageDrag.canDecode(e) ) {
+ QImageDrag.decode(e, img);
+ tmp.resize(img.size());
+ tmp.convertFromImage(img);
+ select.setWidth(tmp.width());
+ select.setHeight(tmp.height());
+ select.moveCenter(e.pos());
+ bitBlt(doc.buffer, select.x()+contentsX(), select.y()+contentsY(), tmp,0,0,tmp.width(), tmp.height());
+ doc.setModified();
+ doc.updateAllViews(this);
+ }
+ action = IDLE;
+ viewport().repaint(0,0,visibleWidth(), visibleHeight(), false);
+ }
+
+}
diff --git a/kdejava/koala/examples/kscribble/Main.java b/kdejava/koala/examples/kscribble/Main.java
new file mode 100644
index 00000000..28d2fe96
--- /dev/null
+++ b/kdejava/koala/examples/kscribble/Main.java
@@ -0,0 +1,78 @@
+/***************************************************************************
+ KScribble.java - KScribble using java bindings
+ -------------------
+ begin : Mon Jan 31 11:05:05 CET 2000
+ copyright : (C) 2000 by Ralf Nolden
+ email : Ralf.Nolden@post.rwth-aachen.de
+ java translation : Kenneth J. Pouncey
+ email : kjpou@hotmail.com
+ ***************************************************************************/
+
+
+import java.util.*;
+import org.kde.qt.*;
+import org.kde.koala.*;
+
+/**
+ * The base class for JavaApiTest application windows. It sets up the main
+ * window and reads the config file as well as providing a menubar, toolbar
+ * and statusbar. An instance of KBaseView creates your center view, which is connected
+ * to the window's Doc object.
+ * KBase reimplements the methods that KMainWindow provides for main window handling and supports
+ * full session management as well as using KActions.
+ * @see KMainWindow
+ * @see KApplication
+ * @see KConfig
+ *
+ * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
+ * @version KDevelop version 1.2 code generation
+ */
+public class Main {
+
+ static String description = "java KDE 3 example application";
+
+
+ static String[][] options = {
+ { "+[File]", "image file to open", null }
+ };
+
+static String VERSION = "0.1";
+
+ public static void main(String[] cmdLineArgs) {
+
+ KAboutData aboutData = new KAboutData( "kscribble", "KScribble",
+ VERSION, description, KAboutData.License_GPL,
+ "(C) 2000 by Ralf Nolden");
+ KCmdLineArgs.init( cmdLineArgs, aboutData );
+ KCmdLineArgs.addCmdLineOptions( options ); // Add our own options.
+
+ KApplication app = new KApplication();
+ KImageIO.registerFormats();
+ KScribbleApp kscribbleapp = new KScribbleApp();
+
+ if (app.isRestored()) {
+ kscribbleapp.RESTORE("kscribbleapp");
+ }
+ else {
+ kscribbleapp.show();
+ KCmdLineArgs args = KCmdLineArgs.parsedArgs();
+
+ if (args.count() > 0) {
+ kscribbleapp.openDocumentFile(new KURL(args.arg(0)));
+ }
+ else {
+ kscribbleapp.openDocumentFile();
+ }
+ args.clear();
+ }
+
+ app.exec();
+ return;
+ }
+
+ static {
+ qtjava.initialize();
+ kdejava.initialize();
+ }
+
+}
diff --git a/kdejava/koala/examples/kscribble/Resource.java b/kdejava/koala/examples/kscribble/Resource.java
new file mode 100644
index 00000000..8277dea6
--- /dev/null
+++ b/kdejava/koala/examples/kscribble/Resource.java
@@ -0,0 +1,71 @@
+
+ ///////////////////////////////////////////////////////////////////
+ // resource.h -- contains macros used for commands
+public interface Resource {
+
+ ///////////////////////////////////////////////////////////////////
+ // COMMAND VALUES FOR MENUBAR AND TOOLBAR ENTRIES
+
+
+ ///////////////////////////////////////////////////////////////////
+ // File-menu entries
+ static final int ID_FILE_NEW = 10010;
+ static final int ID_FILE_OPEN = 10020;
+ static final int ID_FILE_OPEN_RECENT = 10030;
+ static final int ID_FILE_CLOSE = 10040;
+
+ static final int ID_FILE_SAVE = 10050;
+ static final int ID_FILE_SAVE_AS = 10060;
+
+ static final int ID_FILE_PRINT = 10070;
+
+ static final int ID_FILE_QUIT = 10080;
+
+ ///////////////////////////////////////////////////////////////////
+ // Edit-menu entries
+ static final int ID_EDIT_UNDO = 11010;
+ static final int ID_EDIT_COPY = 11020;
+ static final int ID_EDIT_CUT = 11030;
+ static final int ID_EDIT_PASTE = 11040;
+ static final int ID_EDIT_CLEAR_ALL = 11050;
+
+ ///////////////////////////////////////////////////////////////////
+ // Pen-menu entries
+ static final int ID_PEN_COLOR = 14010;
+ static final int ID_PEN_BRUSH = 14020;
+
+ ///////////////////////////////////////////////////////////////////
+ // Draw-menu entries
+ static final int ID_DRAW_FIND = 15010;
+ static final int ID_DRAW_FREEHAND = 15020;
+ static final int ID_DRAW_LINE = 15030;
+ static final int ID_DRAW_RECT = 15040;
+ static final int ID_DRAW_RECT_FILL = 15050;
+ static final int ID_DRAW_CIRCLE = 15060;
+ static final int ID_DRAW_CIRCLE_FILL = 15070;
+ static final int ID_DRAW_ELLIPSE = 15080;
+ static final int ID_DRAW_ELLIPSE_FILL = 15090;
+ static final int ID_DRAW_SPRAY = 15100;
+ static final int ID_DRAW_FILL = 15110;
+ static final int ID_DRAW_ERASE = 15120;
+
+ ///////////////////////////////////////////////////////////////////
+ // View-menu entries
+ static final int ID_VIEW_TOOLBAR = 12010;
+ static final int ID_VIEW_STATUSBAR = 12020;
+
+ ///////////////////////////////////////////////////////////////////
+ // Window-menu entries
+ static final int ID_WINDOW_NEW_WINDOW = 13010;
+ static final int ID_WINDOW_CASCADE = 13020;
+ static final int ID_WINDOW_TILE = 13030;
+
+ ///////////////////////////////////////////////////////////////////
+ // Help-menu entries
+ static final int ID_HELP_CONTENTS = 1002;
+ static final int ID_HELP_WHATS_THIS = 1003;
+ ///////////////////////////////////////////////////////////////////
+ // General application values
+ static final int ID_STATUS_MSG = 1001;
+ static final int TOOLS_TOOLBAR = 1;
+} \ No newline at end of file
diff --git a/kdejava/koala/examples/simplemail/MailHelper.java b/kdejava/koala/examples/simplemail/MailHelper.java
new file mode 100644
index 00000000..b7fa8aba
--- /dev/null
+++ b/kdejava/koala/examples/simplemail/MailHelper.java
@@ -0,0 +1,220 @@
+//package com.werpu.simplemail;
+
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+/**
+ *
+ * @author Werner Punz werpu@gmx.at
+ * @version 1.0
+ * This is a basic Mailer class built upon the JavaMail API
+ * it only does SMTP.
+ */
+public class MailHelper
+{
+
+ private String message = "";
+
+ private String recipient = "";
+
+ private String server = "";
+
+ private String password = "";
+
+ private String sender = "";
+
+ private String subject = "";
+
+ private String username = "";
+
+ private LinkedList ccAddresses = new LinkedList();
+
+ /** Creates a new instance of LC_Mailer */
+ public MailHelper()
+ {
+ }
+
+ /** Getter for property message.
+ * @return Value of property message.
+ */
+ public String getMessage()
+ {
+ return message;
+ }
+
+ /** Setter for property message.
+ * @param message New value of property message.
+ */
+ public void setMessage(String message)
+ {
+ this.message = message;
+ }
+
+ /** Getter for property password.
+ * @return Value of property password.
+ */
+ public String getPassword()
+ {
+ return password;
+ }
+
+ /** Setter for property password.
+ * @param password New value of property password.
+ */
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ /** Getter for property recipient.
+ * @return Value of property recipient.
+ */
+ public String getRecipient()
+ {
+ return recipient;
+ }
+
+ /** Setter for property recipient.
+ * @param recipient New value of property recipient.
+ */
+ public void setRecipient(String recipient)
+ {
+ this.recipient = recipient;
+ }
+
+ /** Getter for property sender.
+ * @return Value of property sender.
+ */
+ public String getSender()
+ {
+ return sender;
+ }
+
+ /** Setter for property sender.
+ * @param sender New value of property sender.
+ */
+ public void setSender(String sender)
+ {
+ this.sender = sender;
+ }
+
+ /** Getter for property server.
+ * @return Value of property server.
+ */
+ public String getServer()
+ {
+ return server;
+ }
+
+ /** Setter for property server.
+ * @param server New value of property server.
+ */
+ public void setServer(String server)
+ {
+ this.server = server;
+ }
+
+ /** Getter for property subject.
+ * @return Value of property subject.
+ */
+ public String getSubject()
+ {
+ return subject;
+ }
+
+ /** Setter for property subject.
+ * @param subject New value of property subject.
+ */
+ public void setSubject(String subject)
+ {
+ this.subject = subject;
+ }
+
+ /**
+ * Method setUsername.
+ * @param username
+ */
+ public void setUsername(String username)
+ {
+ this.username = username;
+ }
+
+ /**
+ * Method addCCAddress.
+ * @param ccAddresses
+ * Adds a single CC Adress to the current CC Addresses
+ */
+ public void addCCAddress(String ccAddresses)
+ {
+ if (!ccAddresses.equalsIgnoreCase("null"))
+ this.ccAddresses.add(ccAddresses);
+ }
+
+ /**
+ * Method addCCAddress.
+ * @param ccAddresses
+ * adds the ccAddresses to the current messaging parameters
+ */
+ public void addCCAddress(Iterator ccAddresses)
+ {
+
+ while (ccAddresses.hasNext())
+ addCCAddress((String) ccAddresses.next());
+ }
+
+ /**
+ * Method send.
+ * @throws MessagingException
+ * sends out the mail with the set messaging parameters
+ */
+ public void send() throws MessagingException
+ {
+ Properties props = new Properties();
+ Session session = Session.getDefaultInstance(props, null);
+
+
+ Address to = new InternetAddress(getRecipient());
+ Address from = new InternetAddress(getSender());
+
+ //only one from address
+ Address[] froms = new Address[1];
+ froms[0] = from;
+
+ MimeMessage message = new MimeMessage(session);
+ message.setText(getMessage());
+ message.setSubject(getSubject());
+ message.addRecipient(Message.RecipientType.TO, to);
+
+ //Add CCs to the recipient list
+ Iterator i = ccAddresses.iterator();
+ while (i.hasNext())
+ {
+ to = new InternetAddress((String) i.next());
+ message.addRecipient(Message.RecipientType.BCC, to);
+ }
+
+ message.addFrom(froms);
+ message.saveChanges();
+
+
+ //set smtp
+ Transport myTransport = session.getTransport("smtp");
+
+ //send mail
+ myTransport.connect(getServer(), username.trim(), password.trim());
+
+ myTransport.sendMessage(message,message.getAllRecipients());
+ myTransport.close();
+ }
+
+}
diff --git a/kdejava/koala/examples/simplemail/README b/kdejava/koala/examples/simplemail/README
new file mode 100644
index 00000000..b48e131d
--- /dev/null
+++ b/kdejava/koala/examples/simplemail/README
@@ -0,0 +1,29 @@
+Werner Punz writes:
+
+A simple send the email app I hacked together today in 2 hours, feel
+ free to add it to the repository...
+
+ This time I used the QT designer and the provided sed script to convert
+ the files into near-java files and then started from there.
+
+First you need JDK 1.2+ since a LinkedList ist used.
+ Secondly you have to have the javamail and activation jar files in the
+ classpath otherwise it won?t work! Those are not part of the standard JDK
+ distro, and haven? t made it into 1.4 yet, but nevertheless are great APIs
+ to access email and nntp systems easily (actually activation isn? t but
+ javamail depends on it).
+
+ Both can be obtained from the Sun java website.
+
+ Here are the links to these api's taken from one of my readme's
+
+ 1. Download the e-mail api's from sun.  You will need two packages.
+
+    http://java.sun.com/products/javamail/
+    http://java.sun.com/products/javabeans/glasgow/jaf.html
+
+ Ah yes you can add multiple BCCs simply by separating them with a ',' or a
+ ';'.
+
+ Thats all have much fun with it :-).
+
diff --git a/kdejava/koala/examples/simplemail/SimpleMailFrm.java b/kdejava/koala/examples/simplemail/SimpleMailFrm.java
new file mode 100644
index 00000000..957ad385
--- /dev/null
+++ b/kdejava/koala/examples/simplemail/SimpleMailFrm.java
@@ -0,0 +1,240 @@
+// package com.werpu.simplemail;
+
+
+/**
+ * SimpleMailFrm
+ * This is the main window from of the simple mail application
+ * @author Werner Punz werpu@gmx.at
+ * This class was generated by Qt Designer and then converted to Java and
+ * redesigned to fit into the KDE Framework
+ */
+
+import org.kde.qt.*;
+import org.kde.koala.*;
+import java.util.StringTokenizer;
+import java.util.LinkedList;
+
+
+
+class SimpleMailFrm extends KMainWindow {
+
+
+ QGroupBox groupBox1;
+ KLineEdit txtServer;
+ KLineEdit txtUserName;
+ KPasswordEdit txtPassword;
+ QLabel textLabel1;
+ QLabel textLabel2;
+ QLabel textLabel3;
+ KLineEdit txtFrom;
+ KLineEdit txtTo;
+ KLineEdit txtBCC;
+ QLabel textLabel4;
+ QLabel textLabel6;
+ QLabel textLabel5;
+ KPushButton btSend;
+ KPushButton btCancel;
+ QMultiLineEdit txtMessage;
+
+
+ QGridLayout form1Layout;
+ QGridLayout groupBox1Layout;
+
+ KApplication parentApp = null;
+
+ public SimpleMailFrm(KApplication kApp)
+
+ {
+ super( null, null,0);
+ parentApp = kApp;
+
+
+ resize( 582, 486 );
+ setCaption( trUtf8( "Simple Mailer" ) );
+
+ QGroupBox centralBox = new QGroupBox((QWidget) this,"");
+
+ form1Layout = new QGridLayout(centralBox, 1, 1, 11, 6, "form1Layout");
+
+ groupBox1 = new QGroupBox( centralBox, "groupBox1" );
+ groupBox1.setTitle( trUtf8( "Mailserver data" ) );
+ groupBox1.setColumnLayout(0, Qt.Vertical );
+ groupBox1.layout().setSpacing( 6 );
+ groupBox1.layout().setMargin( 11 );
+ groupBox1Layout = new QGridLayout( groupBox1.layout() );
+ groupBox1Layout.setAlignment( Qt.AlignTop );
+
+ txtServer = new KLineEdit( groupBox1, "txtServer" );
+
+ groupBox1Layout.addWidget( txtServer, 0, 1 );
+
+ txtUserName = new KLineEdit( groupBox1, "txtUserName" );
+
+ groupBox1Layout.addWidget( txtUserName, 1, 1 );
+
+ txtPassword = new KPasswordEdit( groupBox1, "txtPassword" );
+
+ groupBox1Layout.addWidget( txtPassword, 2, 1 );
+
+ textLabel1 = new QLabel( groupBox1, "textLabel1" );
+ textLabel1.setText( trUtf8( "Server" ) );
+
+ groupBox1Layout.addWidget( textLabel1, 0, 0 );
+
+ textLabel2 = new QLabel( groupBox1, "textLabel2" );
+ textLabel2.setText( trUtf8( "Username" ) );
+
+ groupBox1Layout.addWidget( textLabel2, 1, 0 );
+
+ textLabel3 = new QLabel( groupBox1, "textLabel3" );
+ textLabel3.setText( trUtf8( "Password" ) );
+
+ groupBox1Layout.addWidget( textLabel3, 2, 0 );
+
+ txtFrom = new KLineEdit( groupBox1, "txtFrom" );
+
+ groupBox1Layout.addWidget( txtFrom, 0, 3 );
+
+ txtTo = new KLineEdit( groupBox1, "txtTo" );
+
+ groupBox1Layout.addWidget( txtTo, 1, 3 );
+
+ txtBCC = new KLineEdit( groupBox1, "txtBCC" );
+
+ groupBox1Layout.addWidget( txtBCC, 2, 3 );
+
+ textLabel4 = new QLabel( groupBox1, "textLabel4" );
+ textLabel4.setText( trUtf8( "From" ) );
+
+ groupBox1Layout.addWidget( textLabel4, 0, 2 );
+
+ textLabel6 = new QLabel( groupBox1, "textLabel6" );
+ textLabel6.setText( trUtf8( "BCC" ) );
+
+ groupBox1Layout.addWidget( textLabel6, 2, 2 );
+
+ textLabel5 = new QLabel( groupBox1, "textLabel5" );
+ textLabel5.setText( trUtf8( "To" ) );
+
+ groupBox1Layout.addWidget( textLabel5, 1, 2 );
+
+ form1Layout.addMultiCellWidget( groupBox1, 0, 0, 0, 1 );
+
+ btSend = new KPushButton( centralBox, "btSend" );
+ btSend.setText( trUtf8( "Send" ) );
+
+ form1Layout.addWidget( btSend, 2, 0 );
+
+ btCancel = new KPushButton( centralBox, "btCancel" );
+ btCancel.setText( trUtf8( "Cancel" ) );
+
+ form1Layout.addWidget( btCancel, 2, 1 );
+
+ txtMessage = new QMultiLineEdit(centralBox, "txtMessage" );
+
+ form1Layout.addMultiCellWidget( txtMessage, 1, 1, 0, 1 );
+
+ setCentralWidget(centralBox);
+ // tab order
+ setTabOrder( txtServer, txtUserName );
+ setTabOrder( txtUserName, txtPassword );
+ setTabOrder( txtPassword, txtFrom );
+ setTabOrder( txtFrom, txtTo );
+ setTabOrder( txtTo, txtBCC );
+ setTabOrder( txtBCC, txtMessage );
+ setTabOrder( txtMessage, btSend );
+ setTabOrder( btSend, btCancel );
+
+ setEventHandlers();
+ }
+
+ //----------------------------------------------------------
+ // Getter Methods to access the data outside of the
+ // current class
+ //----------------------------------------------------------
+
+ public String getServer() {
+ return txtServer.text();
+ }
+
+ public String getUserName() {
+ return txtUserName.text();
+ }
+
+ public String getPassword() {
+ return txtPassword.text();
+ }
+
+ public String getFrom() {
+ return txtFrom.text();
+ }
+
+ public String getTo() {
+ return txtTo.text();
+ }
+
+ public String getBCC() {
+ return txtBCC.text();
+ }
+
+ public String getMessage() {
+ return txtMessage.text();
+ }
+
+ void setEventHandlers() {
+ connect( btCancel, SIGNAL("clicked()"), parentApp, SLOT("quit()"));
+ connect( btSend,SIGNAL("clicked()"),this,SLOT("sendMail()"));
+ }
+
+
+ //--------------------------------------------
+ // Slots
+ //-------------------------------------------
+ public void sendMail() {
+ String server = getServer();
+ String userName = getUserName();
+ String password = getPassword();
+ String from = getFrom();
+ String to = getTo();
+ String message = getMessage();
+ LinkedList bccs = getBCCs();
+
+ try {
+ MailHelper mailer = new MailHelper();
+ mailer.setMessage(message);
+ mailer.setSubject("Simple Mail");
+ mailer.setSender(from);
+ mailer.setRecipient(to);
+ mailer.addCCAddress(bccs.iterator());
+ mailer.setServer(server);
+ mailer.setUsername(userName);
+ mailer.setPassword(password);
+ mailer.send();
+ }
+ catch (Exception ex) {
+ KMessageBox.error(this , ex.getMessage());
+ return;
+ }
+ KMessageBox.information(this,"Mail was successfully sent!");
+ }
+
+ //-------------------------------------
+ //Helpers
+ //-------------------------------------
+
+ /**
+ * Split the BCCs into single entries if nedded
+ */
+ LinkedList getBCCs() {
+ LinkedList retVal = new LinkedList();
+
+ String bcc = getBCC();
+ StringTokenizer splitter = new StringTokenizer(bcc,",;");
+
+ while(splitter.hasMoreTokens())
+ retVal.add(splitter.nextToken());
+
+ return retVal;
+ }
+}
+
diff --git a/kdejava/koala/examples/simplemail/SimpleMailer.java b/kdejava/koala/examples/simplemail/SimpleMailer.java
new file mode 100644
index 00000000..bd30f2da
--- /dev/null
+++ b/kdejava/koala/examples/simplemail/SimpleMailer.java
@@ -0,0 +1,39 @@
+//package com.werpu.simplemail;
+
+import org.kde.qt.*;
+import org.kde.koala.*;
+
+
+/**
+ *
+ * @author Werner Punz werpu@gmx.at
+ * This is a simple mailer to demonstrate the connection
+ * of KDE Java with java packages.
+ * It demonstrates the connection between KDEJava and the javamail API
+ * to send mails from a KDE Application box via the SMTP protocol
+ * Note:The javamail and activation jar files have to be in your classpath!
+ *
+ */
+public class SimpleMailer extends KApplication{
+ static {
+ qtjava.initialize();
+ kdejava.initialize();
+ }
+
+ public SimpleMailer() {
+ super();
+ SimpleMailFrm mainWidget = new SimpleMailFrm(this);
+ this.setMainWidget(mainWidget);
+ mainWidget.show();
+ this.exec();
+ }
+
+ /**
+ * Entry point for the program
+ */
+ public static void main(String [] argv) {
+ KCmdLineArgs.init(argv, "simplemailer", "SimpleMailer",
+ "Simple Mailing Application", "0.1");
+ SimpleMailer mailClnt = new SimpleMailer();
+ }
+}