JetCracker

Life-time learner's blog

Tag Archives: netbeans

Ctrl+Space doesn’t work in NetBeans [Ubuntu 12.04] [Solved]

I reinstalled Ubuntu on my laptop recently. Now I am using Ubuntu 12.04 LTS with Gnome 3 environment. Everything worked fine except one problem: the hot key Ctrl+Space (auto code completion) stopped working in Netbeans and other IDE. Of course, there was an alternative key combination Ctrl+’\’, but it is absolutely inconvenient! I’d prefer to kill myself looking for the solution on the Internet rather than to give in and use Ctrl+’\’. I’ve surfed the net for a while and found a solution to my problem!

The key combination didn’t work because some other program used it. To fix this I used gconf-editor.

  1. Open gconf-editor.
  2. Choose desktop -> ibus -> general -> hotkey.
  3. Open trigger parameter.
  4. Remove Ctrl+Space key combination from the list and press OK.

Now we can use Ctrl+Space without any problems. Let me know if you have any problems or/and better ideas. Good luck!
UPD: I returned to Ubuntu 11.10, cuz’ 12.04 turned out to be a total rubbish. I’m just wondering if Ubuntu 12.10 is any better…

Logging in Java: Fast introduction. Basic standards and guidelines

Logging is used to track the execution flow of the programme. It’s is also useful for debugging your application when an interactive debugging is not available (e.g. in web-applications).

All good and sophisticated programmes have logging. Just look into Windows Event log and you will find a lot of interesting things, which are happening under the covers of friendly GUI of this amazing OS. 😉

The simplest way to log is to write what is happening to Console or to file. But you always have to think about the format of log. And there is a problem of storing log files on disk. Today, there are lots of logging engines for different programming languages and platforms, which significantly simplify dealing with logs. In Java the most popular are Apache log4j, SLF4J, LogBACK. Last two ones are becoming more and more popular, but I’d like to be conservative and tell about log4j. It’s classic! Read more of this post

NetBeans 6.9: Java + Scala – How to compile

Scala Logo

Начнем сразу с проблемы:

Требуется скомпилить вот такой код в среде NetBeans 6.9:

package scala1

import java.awt._;
import java.util._;
import javax.imageio.stream._;
import javax.imageio._;
import java.io.File;
import java.awt.image.BufferedImage;

class Complex(val x : Double, val y : Double) {
  def +(c : Complex) = new Complex(x + c.x, y + c.y)
  def -(c : Complex) = new Complex(x - c.x, y - c.y)
  def *(c : Complex) = new Complex(x * c.x - y * c.y, x * c.y + y * c.x)
  def mod2() = x*x + y*y
  override def toString() = x + "+i" + y
}

object Main {

  def steps(c : Complex, max : Int): Int = {
    var z = new Complex(0, 0)
    for (i <- 0 to max) {
      z = z*z + c
      if (z.mod2 > 4) {
	return i
      }
    }
    return 0
  }

  def main(args: Array[String]) {
    val width = 1000
    val height = 600

    val img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    val g = img.getGraphics();

    val viewX = -0.2;
    val viewY = -1.0;
    val viewW = 0.5;
    val viewH = 0.25;
    val dx = 1.0/width; val dy = 1.0/height

    for (y <- 0 to height) {
      for (x <- 0 to width) {
	val p:Double = viewW * (dx*x) + viewX
	val q:Double = viewH * (dy*y) + viewY
	val c = new Complex(p,q)
	val s: Int = steps(c, 255)
	g.setColor(new Color(s/3, s/3, s))
	g.drawLine(x,y,x,y)
      }
    }
    ImageIO.write(img, "png", new File("copmlex-graph.png"));
  }

}

Для того чтобы NetBeans умела работать с языком Scala, нужно установить Scala Kit. К сожалению, в списке доступных плагинов Scala Kit отсутствует, поэтому будем ставить его вручную.

  1. Качаем плагин для NetBeans 6.9 тут: http://sourceforge.net/projects/erlybird/files/nb-scala/
  2. Распаковываем архив во временную папку.
  3. В NetBeans открываем Tools->Plugins и переходим на вкладку Downloaded
  4. Жмем кнопку Add Plugin… и выбираем все распакованные файлы
  5. Устанавливаем плагины
  6. Закрываем NetBeans
  7. Правим файл ~/.bash_profile в любом редакторе, добавляя в него код:
#/usr/bin/sh
export SCALA_HOME=~/scala

Здесь SCALA_HOME – путь к папке, где установлена Scala. Я прописал переменную окружения в скрипте ~/.bash_profile, который стартует во время входа пользователя в систему. Поэтому, чтобы изменения вступили в силу, необходимо выйти из системы и зайти в нее снова.

Ну а теперь можно насладиться программированием на языке Scala в удобной среде NetBeans. 🙂

P.S. Программа в листинге рисует множество Мандельброта. Вот, что может быть результатом ее исполнения:

  Множество Мандельброта (красный)