SWT migration to GTK+ 3.x : What is GDK ? What is GIMP ?

23 May

This is third post related to my new project – migration of SWT from GTK+ 2.x to GTK+ 3.x .

In order to successfully build SWT with GTK+ 3.x all deprecations must be resolved. Big chunk of deprecated methods are GDK methods.

What is GDK ?

GDK is GIMP Drawing Kit. Wikipedia states that GDK  “is a computer graphics library that acts as a wrapper around the low-level drawing and windowing functions provided by the underlying graphics system….GDK lies between the X server and the GTK+ library, handling basic rendering such as drawing primitives, raster graphics (bitmaps), cursors, fonts, as well as window events and drag-and-drop functionality.” ( more on GDK here )

GDK has a lot of tools for most of the use cases  that one might need. I have found very informative GDK reference manual on their website .

What is GIMP ?

If GDK is GIMP Drawing Kit, it would be important to find out – What is GIMP. Thankfully GIMP has huge website that describes what it does in many languages. If you are interested, please visit   http://www.gimp.org  to find out more.

Making story short – GIMP is open-source drawing software used for image editing, free-form drawing and other manipulation with images and photos.

GIMP Screenshot

Image is taken from: http://redskiesatnight.com

GDK was originally developed for GIMP, however  it is used in many  places including SWT as GIMP toolkit called GTK+. With new release of GTK+, several steps needed to be taken to successfully migrate from old GTK+ 2.x to new GTK+ 3.x. As I have already mentioned -  one of the major steps is to implement Cairo library for drawing instead of deprecated GDK methods.

 

Tags: , , , , , , , , ,

SWT migration from GTK+ 2.x to GTK+ 3.x : Introduction

17 May

In the earlier post I was exploring Standard Widget Toolkit. I have created simple application to see how SWT works. In this post I want to show couple of reasons, why SWT cannot be easily migrated from GTK+ 2.x to GTK 3.x .

Let’s approach this issue step by step.

What is GTK + ?   

As I have found out from GTK+ Project website (http://www.gtk.org/)   ” GTK+, or the GIMP Toolkit, is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets, GTK+ is suitable for projects ranging from small one-off tools to complete application suites.” GTK+ supports most widely used programming languages, thus making it one of the main tools  in User Interface development.

How GTK+ is connected with SWT ?

As I have found out, GTK+ library is widely used in SWT.

How to build SWT with GTK+ 2.x ?

I have pulled SWT source code using tutorial  from here   and built it using following commands:


export JAVA_HOME=/usr/lib/jvm/java

./git/eclipse.platform.swt/bundles/org.eclipse.swt/bin/library

sudo ./build.sh

Everything built just fine.  However, problems started when I tried to built it with GTK+ 3.x.

How to build SWT with GTK+ 3.x ?

To be able to build SWT with GTK+ 3.x I have uncommented line


#define GDK_DISABLE_DEPRECATED

in:


./git/eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/os.h

After doing it, I tried to built again. Unfortunately this time built was not succesful.

Here is the sample of the output:

Building SWT/GTK+ for linux x86
gcc -O -Wall -DSWT_VERSION=4230  -DLINUX -DGTK -I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux -fPIC  `pkg-config --cflags gtk+-2.0` -c os.c
os.c: In function ‘Java_org_eclipse_swt_internal_gtk_OS__1gdk_1bitmap_1create_1from_1data’:
os.c:4930:2: warning: implicit declaration of function ‘gdk_bitmap_create_from_data’ [-Wimplicit-function-declaration]
os.c: In function ‘Java_org_eclipse_swt_internal_gtk_OS__1gdk_1color_1white’:
os.c:5078:2: warning: implicit declaration of function ‘gdk_color_white’ [-Wimplicit-function-declaration]
os.c: In function ‘Java_org_eclipse_swt_internal_gtk_OS__1gdk_1draw_1drawable’:
os.c:5273:2: warning: implicit declaration of function ‘gdk_draw_drawable’ [-Wimplicit-function-declaration]
........

Why SWT cannot be built with GTK+ 3.x ?

After small research I have found out that some of the methods of GTK library that SWT uses are deprecated.
Complete guide on what need to be change to migrate from GTK+ 2.x to GTK+ 3.x can be found here .

Most  depreciation are already resolved, except  ones that are supposed to  use Cairo graphics library  for drawing. Next couple of months, I will be working  on implementing Cairo library into SWT instead of deprecated gdk methods, so it could be successfully migrated to GTK+3.x.

More about Cairo in my next posts…

Tags: , , , , , , , , , ,

What is Standard Widget Toolkit for Eclipse (SWT) ?

15 May

Here I am at my new workplace. Next 8 months I will be working in Eclipse team, on migration of SWT  from GTK2 to GTK3.

If these words does not tell you much, don’t worry, I am pretty much in the same situation, but what I am going to do in the next couple of days is to explore this issue as much as I can, and  write down my findings here.

Let’s start with SWT.  My first stop in finding info about SWT was here: http://www.eclipsepluginsite.com/swt.html

After reading  introductory chapter,  I have  found out that SWT stands for   Standard Widget Toolkit.  As I have understood from the reading, SWT is a collection of tools, intended for creating stand alone java applications or eclipse plugins  with basic UI components (such as buttons, trees etc). What is  special about SWT, is that it uses native OS components, so when you build application with SWT it feels like this application is intended for the particular OS.

I decided to build a simple application using one of the examples provided in the reading.

Simple SWT Application

/*
 *  Name: BlogButton.java
 *  Description:  SWT  button on click changes text and background color
 *
 *  Author: Anatoly Spektor
 *  Date: May 14,2012
 * */

import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.*;

public class BlogButton {

public static void main(String[] args) {
 // creating new object of Display myDisplay
 //in SWT Display manages connection between app and OS
 final Display myDisplay = new Display();
 // creating instance of shell - which is actual window
 Shell myShell = new Shell(myDisplay);

// setting window title
 myShell.setText("Window Title");
 //setting size
 myShell.setSize(400,400);
 // setting layout
 myShell.setLayout(new FillLayout());
 // creating button object in myShell
 // passing PUSH behaviour
 final Button button = new Button(myShell, SWT.PUSH);
 // passing button label
 button.setText("Show Blog URL");

// adding event listener to button
 button.addSelectionListener(new SelectionAdapter() {
 public void widgetSelected(SelectionEvent event) {
 //on selected change button label
 button.setText("myprogrammingblog.com");
 // set text color to red
 button.setForeground(myDisplay.getSystemColor(SWT.COLOR_RED));

}
 });

// open - pushes shell on the top of drawing order and makes it visible
 myShell.open();

// checking if shell is Disposed or not
 while (!myShell.isDisposed()) {
 // check if there is work to do for this shell and if not
 // put it in sleep mode so no CPU is consumed
 if (!myDisplay.readAndDispatch()) myDisplay.sleep();
 }
 // disposing an object
 myDisplay.dispose();
 }
 }

Output:

Before Click:
SWT button before click

After Click:

SWT button after click snapshot

Tags: , , , , , , , , , , ,

My new work: Software Developer – Red Hat

8 May

Now I will be working as Software Developer in Red Hat.   For the blog readers it means that along with the tutorials, and other stuff,  I will have Red Hat related posts. I am sure that this experience will be beneficial not only for me, but for all the blog readers, as I will definitely share my findings with you.

Tags: , , , , ,

My official portfolio: anatolyspektor.com (Anatoly Spektor Official Web Site)

8 May

Hello guys,

As I had a week off from my studies and work, I decided to do something useful. Many of you asked, why I don’t write about myself. So I  have created a small portfolio, where  anyone  can find some info about me and my work. If you are interested – please go to http://www.anatolyspektor.com

 

Any feedback is appreciated!

:)

Tags: , , , , , , , ,

[VIDEO] Polling Module Final Version (Big Blue Button)

24 Apr

The day a lot of people waited for has come. We finally are releasing our module to public. Here is the video that shows all its features.

 

Tags: , , , , , , , , ,

Java – How to format string using SampleDateFormat ?

6 Apr

One of the blog readers asked me this question, how to format string using SampleDateFormat to mm/dd/yyy.

Here is a small piece of code, I hope some of you will find it useful.

a. Frist – import 2 libraries:


import java.text.SimpleDateFormat;
import java.util.Date;

b. Here is code:


Date date = new Date(); // creating date object
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy hh:mm a");
// creating SampleDate object and passing the pattern to constructor ("a" means show AM or PM)
System.out.println( "Here is today's date: " +  formatter.format(date) + ");

//The output: Here is today's date: 04/06/12 10:52 AM

Regards,

Anatoly Spektor

Tags: , , , , , , , , , ,

How to setup TinyMCE using ASP.NET (C#) ? How to customize TinyMCE buttons ?

5 Mar

Today we are going to take a look at one of the most customizable Rich Text Editors for Asp.Net – TinyMCE.

How to setup tinyMCE

In this post I will give you couple of tricks how to easily set  it up, customize and avoid most common problems such as “Required Field Validator” and “A potentially dangerous Request.Form value was detected” errors.

Let’s start.

1. First of all download TinyMCE from here:

http://www.tinymce.com/download/download.php (download first one)

2. Unpack “tinymce” folder to your Web Project root folder.

(My project is divided into Admin and Member sections, and tinymce is used only Admin that’s why I unpacked it in Admin folder)

3. Now go to the page where you will be using TinyMCE and add following code at the top:

<script language="javascript" type="text/javascript">
 tinyMCE.init({
                  mode: "textareas",
                  theme: "advanced",
                  theme_advanced_toolbar_location: "top",
                  theme_advanced_buttons1: "italic,underline,separator,justifyleft,justifycenter,justifyright,separator,formatselect,separator,bullist,numlist,link,unlink",
                  theme_advanced_buttons2: "",
                  theme_advanced_buttons3 : "",
                  encoding: "xml"
 });
</script>
<!--end of code -->

4. Let’s take a look at each line, so you know how to customize your tinyMCE toolbar:

a. mode: “textareas”

- means that it will replace all textareas or

b. theme: “advanced”

      – means that you choose advanced theme

c.  I used “theme_advanced_toolbar_location:

-  because when I first installed tinyMCE toolbar appeared at the bottom. So to fix it I used theme_advanced_toolbar_location property

d. theme_advanced_buttons1:

       -  describes what buttons will appear on first row of toolbar (theme_advanced_buttons2 and 3 describes second and third rows)

List of the buttons is here: http://www.tinymce.com/wiki.php/Buttons/controls

e. encoding: “xml”

- solves  “A potentially dangerous Request.Form value was detected”, which won’t allow you to submit the Web Form

This is all what you need to set up your tinyMCE.

However, there is one more trick that will help you to avoid problem of Required Field Validator saying that your textarea is empty.

5. All you need to do is add following to your textarea or asp:TextBox:

OnClientClick=”tinyMCE.triggerSave(false,true);”

Example:

<asp:Button ID="btnPublish" runat="server" Text="Publish" CssClass="button"
 Height="36px" Width="88px" onclick="btnPublish_Click1"
 ValidationGroup="postValid" OnClientClick="tinyMCE.triggerSave(false,true);"/>

So here what I got:

Tags: , , , , , , , , ,

Java: How to split Java String with delimeter comma, space, new line, tab ? [SOLVED]

20 Feb

Sometimes it is very important to split a string on a comma \n \t etc. This piece of code will help you with it.


import java.util.*;

 public class split{

  public  static void main ( String args[]) {
       // this is my string 
	String s = "Java,	Programming	is ,,, fun do you agree? ."; split
	String regexp = "[\\s,;\\n\\t]+"; // these are my delimiters
	String [] tokens; // here i will save tokens
	// length is 7 because i know that my string will consist of 7 tokens
	for(int i=0;i<7;i++){
		tokens = s.split(regexp);
		System.out.println(tokens[i]);
	}
   }
}

 // tokens are: Java Programming is fun do you agree?

Tags: , , , , , , , , , , , ,

Java: How to find Longest String in ArrayList ? [FUNCTION]

19 Feb

While I was playing with Java code, I have coded a class that has method that finds longest String in the ArrayList. Method is very simple, but I am sure that some of you will find it useful.

So here it is:

 // I have a class attribute:
private ArrayList<String> wordsList = new ArrayList<String>();

// here is method itself:
public String longest_word(){
	String longest_word="";
	int maxLength=0;
		for(int i=0; i<wordsList.size();i++){

			if(wordsList.get(i).length() > maxLength){
			  maxLength = wordsList.get(i).length();
			  longest_word = wordsList.get(i);
			}
		}
	return longest_word;
	}

Tags: , , , , , , , , , ,

Big Blue Button: Updates on Polling Module – How to contribue to Polling Module ?

17 Feb

Hey guy’s,

First of all we  (Seneca CDOT) have some  good news for you :

Our beta version of Polling Module is packaged and very soon will be available for testing.

Also demo video will be available in next 2-4 days.

However we need your help  to localize  the content of Polling Module.

For those of you who know different languages, please, help us to translate  following strings: (everything after ‘=’).

 

Continue reading 

Tags: , , , , , , , , , ,

Polling Module Demo Video – Publish Feature

4 Feb

Tags: , , , , , , , ,

GitHub: How to clone GitHub repo ? How to push to Github? How to get files from GitHub ? (Ubuntu)

20 Jan

GitHub is an online repository. Many people find it very confusing to use GitHub, so I’ve decided to share my experience of using it on Linux Ubuntu.

So in this post we will discuss:

1. How to set up and clone repo to your local machine avoiding message: Permission denied (publickey).
2. How to  transfer all changes you are making INTO Github
3. How to get those changes FROM GitHub

My way could not be the most efficient one, but it works for me. :)

How to setup up GitHub to your local machine ?

So for the first part, you need to download Git and set your SSH key. Thanks to the GitHub documentation,  step by step guide is here:

http://help.github.com/linux-set-up-git/

How to clone your repo to your local machine ?

(in git terminology it’s called “checkout“)

First you need to find your repo address. It can be find  on your GitHub repo page:

Copy the address in the box (git@github.com……/….git)

Open the terminal and go to the folder where you want to have your git to be located.

  Type command:

git clone ADDRESS YOU COPIED

Here is my output:

How to  transfer all changes you are making INTO Github ?

(in GitHub it is called Push)

There are 3 steps to transfer your changes to GitHub:

a. You need to add files  —> git add .

(“.” means all the files, no worries, it will add everything that was changed.)

b. You need to Commit you changes –> git commit  -m “Message you want to see near your commit”

c. Push your changes to the server –> git push

My output:

On the repo I now see that README file has my commit message (I changed only README.txt):

 How to get those changes FROM GitHub ?

git checkout

git pull

These commands will bring all the  new stuff from GitHub to your machine.

Good Luck,

Anatoly

Tags: , , , , , , , ,

Java : How to swap two objects [Problem Solved]

12 Jan

As you might knowJava does not support pointers, thus swapping things around could create problems.  In this post I will show an example of swapping two objects.

 

We have Employee class that holds information about Employees and SwapDemo3 class that will actually swap two employees inside a swap() method.

Swap() method will be using set and get methods of Employee class to get the private data from it.

 

So here is Employee Class we will be working with:

Continue reading 

Merry Christmas!

24 Dec

photo taken from:     http://www.worldofchristmas.net

ActionScript 3.0 – How to find duplicate array elements ? [SOLVED]

12 Dec


    private function hasDuplicates(arr:Array):Boolean{

      var x:uint;
      var y:uint;

    			for (x = 0; x < arr.length ; x++){

        			for (y = x + 1; y < arr.length; y++){

            				if (arr[x] === arr[y]){
                				return true;
            				}

        			}
    			}
    			return false;
		}

  

This small function returns true if array has duplicate elements  or false if there are no duplicates.

So if you have array “test1″ and you need to make sure there are no duplicates, you could do something like this:


  if( !hasDuplicates(test1) ) // if there are no duplicates it will return "true" in this case

           trace ("There are no duplicates in array test1");

    

Have fun,

Anatoly

Tags: , , , ,

Top 10 most useful WordPress plugins 2011

28 Nov

The end of the year is coming, and for  my blog it is very exciting time to look back at the great products that were popular in the past 11 months. I have received many emails from you, dear blog readers, asking  me to overview some of the hottest WordPress plug-ins of 2011-2012.

Frankly, I found the idea of creating such top very exciting, so it is a great pleasure of mine, to introduce you, “Top 10 most  useful WordPress plugins 2011 by myprogrammingblog.com “.

10.  Category and Page Icons

   Category: Interface

    This plug-in adds custom icons to navigation menu items, without css. Icons are connected directly to menu item, thus you can press on them like simple button.

9.  Topsy Retweet Button

Category: Social Networking

Good News: Tweeter is still alive and popular. Users like to re-tweet favorite posts. Topsy had created nice plug-in with a  variety of designs. It is much more stable, than  a popular TweetMeme.

Continue reading 

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Big Blue Button – Polling Module – New feature! PollPreview [Demo Video]

18 Nov

Tags: , , , , ,

ActionScript 3 How to redraw/refresh Canvas ?

17 Nov

Use this two functions:


         invalidateDisplayList();
          validateNow();

Good Luck,

Anatoly

Tags: , , , ,

ActionScript 3, Flex 4 Script – How to dynamically create CheckBoxes, RadioButtons and add them to the View

17 Nov

Couple of hours I was “googling” to  find the best solution on how to create Checkboxes and Radio Buttons on fly in ActionScript 3  under Flex4. Unfortunately for me, everything, that  I was able to find was either outdated, or just not for me. So I created my script from scratch, and  decided to share it with you, so you could re-use it in your projects ( don’t forget to link on me :) ).

I have made a lot of comments so you could easier understand how it works, but if you have questions, please ask. Also  this function is easy editable so you could adopt it to your needs.


// function receives Array.length and ArrayCollection
private function createButtons(amount:uint, content:ArrayCollection):void{

  var _cb:CheckBox;
  var _rb:RadioButton;
  var _tx: Text;
  var _hb: HBox;

      // creating buttons one by one
      for (var i:int = 0; i < amount; i++) {

          _tx = new Text();
          _hb = new HBox();
          _tx.name = "option" +i;
          _tx.width = 200;

      // assigning array element to text field

          _tx.text =content.getItemAt(i).toString();

     //adding HBox to the view

          options.addChild(_hb);

     // if global var _isMultiple is true  drawcheckboxes,
     // otherwise radioButtons

          if(_isMultiple){

                 _cb= new CheckBox();

                   // giving button a name of array element to process it easier later

                _cb.name=content.getItemAt(i).toString();

               // defining gap between the buttons

                _cb.y=i*20;

              // adding buttons to the Horizontal Box

               _hb.addChild(_cb);

         }else{ // if not _isMultiple

               _rb = new RadioButton();

                // giving button a name of array elelment to process it easier later

               _rb.name = content.getItemAt(i).toString();

                // assigning radio to the same group

               _rb.groupName = "answers";
                _rb.label ="*";	

                _hb.addChild(_rb);

         }
        // adding text near button

         _hb.addChild(_tx);

      } // end of loop

} // end of function

 

options is repesented as:


       <mx:Box id="options" >
        </mx:Box>

Here is what I’ve got (when _isMultiple is false):

Cheers,

Anatoly

Tags: , , , , , , , , , , , , , ,

Follow

Get every new post delivered to your Inbox.

Join 226 other followers