Book Image

Eclipse Plug-in Development Beginner's Guide - Second Edition

By : Alex Blewitt
Book Image

Eclipse Plug-in Development Beginner's Guide - Second Edition

By: Alex Blewitt

Overview of this book

Eclipse is used by everyone from indie devs to NASA engineers. Its popularity is underpinned by its impressive plug-in ecosystem, which allows it to be extended to meet the needs of whoever is using it. This book shows you how to take full advantage of the Eclipse IDE by building your own useful plug-ins from start to finish. Taking you through the complete process of plug-in development, from packaging to automated testing and deployment, this book is a direct route to quicker, cleaner Java development. It may be for beginners, but we're confident that you'll develop new skills quickly. Pretty soon you'll feel like an expert, in complete control of your IDE. Don't let Eclipse define you - extend it with the plug-ins you need today for smarter, happier, and more effective development.
Table of Contents (24 chapters)
Eclipse Plug-in Development Beginner's Guide Second Edition
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – drawing a seconds hand


A clock with no hands and no numbers is just a circle. To change this, a second hand will be drawn using a filled arc.

Since arcs are drawn anticlockwise from 0 (on the right, or 3 o'clock) through 90 degrees (12 o'clock), then 180 degrees (9 o'clock), then 270 degrees (6 o'clock), and finally back to 360 degrees (3 o'clock), it is possible to calculate the arc's position for the second hand using the expression (15 – seconds) * 6 % 360.

  1. Go to the drawClock method of the ClockView class.

  2. Add a variable called seconds that is initialized to LocalTime.now().getSecond().

  3. Get the SWT.COLOR_BLUE via the display, and store it in a local variable, blue.

  4. Set the background color of the graphics context to blue.

  5. Draw an arc using the formula mentioned earlier to draw the second hand.

  6. The code should look like this:

    public void paintControl(PaintEvent e) {
      e.gc.drawArc(e.x, e.y, e.width-1, e.height-1, 0, 360);
      int seconds = LocalTime.now().getSecond();
      int arc...