update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / HSpacer.java
blobc5f8f066069dcc9719d9040c598aa2e0b8fcf4a4
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.uiDesigner;
18 import com.intellij.util.ui.UIUtil;
20 import java.awt.*;
22 /**
23 * @author Anton Katilin
24 * @author Vladimir Kondratyev
26 public final class HSpacer extends DesignSpacer{
27 public HSpacer(){
28 setSize(50,getHandleHeight());
31 protected void paintComponent(final Graphics g){
32 final int handleHeight=getHandleHeight();
33 final int handleWidth=getHandleWidth();
35 // Paint left handle
36 final int y=(getHeight()-handleHeight)/2;
37 drawHandle(g,0,y);
38 g.setColor(ourColor1);
39 UIUtil.drawLine(g, handleWidth, y + handleHeight / 2, handleWidth + 1, y + handleHeight / 2);
41 // Paint right handle
42 final int x=getWidth()-handleWidth-1;
43 drawHandle(g,x,y);
44 UIUtil.drawLine(g, x, y + handleHeight / 2, x - 2, y + handleHeight / 2);
45 g.setColor(ourColor1);
47 // Draw spring
48 drawSpring(g,handleWidth+1,y+handleHeight/2,getWidth()-2*handleWidth-4);
51 private static int getHandleWidth(){
52 return HANDLE_ATOM_WIDTH;
55 private static int getHandleHeight(){
56 return HANDLE_ATOM_HEIGHT*3 + HANDLE_ATOM_SPACE*2;
59 /**
60 * Paints small spacer's haldle. <code>(x,y)</code> is a top
61 * left point of a handle.
63 private static void drawHandle(final Graphics g,final int x,int y){
64 g.setColor(ourColor1);
66 g.drawRect(x,y,HANDLE_ATOM_WIDTH-1,HANDLE_ATOM_HEIGHT-1);
67 UIUtil.drawLine(g, x + HANDLE_ATOM_WIDTH / 2, y + HANDLE_ATOM_HEIGHT, x + HANDLE_ATOM_WIDTH / 2,
68 y + HANDLE_ATOM_HEIGHT + HANDLE_ATOM_SPACE - 1);
70 y+=HANDLE_ATOM_HEIGHT+HANDLE_ATOM_SPACE;
72 g.drawRect(x,y,HANDLE_ATOM_WIDTH-1,HANDLE_ATOM_HEIGHT-1);
73 UIUtil.drawLine(g, x + HANDLE_ATOM_WIDTH / 2, y + HANDLE_ATOM_HEIGHT, x + HANDLE_ATOM_WIDTH / 2,
74 y + HANDLE_ATOM_HEIGHT + HANDLE_ATOM_SPACE - 1);
76 y+=HANDLE_ATOM_HEIGHT+HANDLE_ATOM_SPACE;
78 g.drawRect(x,y,HANDLE_ATOM_WIDTH-1,HANDLE_ATOM_HEIGHT-1);
81 private static void drawSpring(final Graphics g,final int x,final int y,final int width){
82 for(int _x=x;_x<x+width-1;_x+=SPRING_PRERIOD){
83 drawSpringPeriod(g,_x,y);
87 private static void drawSpringPeriod(final Graphics g,final int x,final int y){
88 g.setColor(ourColor2);
89 UIUtil.drawLine(g, x, y - 1, x, y - 2);
90 UIUtil.drawLine(g, x + 1, y, x + 1, y);
91 UIUtil.drawLine(g, x + 2, y + 1, x + 2, y + 2);
93 g.setColor(ourColor3);
94 UIUtil.drawLine(g, x + 3, y, x + 3, y);
97 public Dimension getMinimumSize(){
98 return new Dimension(getHandleWidth()*2+SPRING_PRERIOD,getHandleHeight());