Menu

[r65]: / trunk / src / VisualLogic / SelectionPane.java  Maximize  Restore  History

Download this file

339 lines (279 with data), 9.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
MyOpenLab by Carmelo Salafia www.myopenlab.de
Copyright (C) 2004 Carmelo Salafia cswi@gmx.de
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package VisualLogic;
import java.awt.AWTEvent;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JPanel;
/**
*
* @author Carmelo
*/
public class SelectionPane extends JPanel implements MouseListener, MouseMotionListener, KeyListener
{
private Element element;
private boolean alwaysOnTop=false;
private Color colorSelected=new Color(255,0,0,110);
private Color colorInavtive=new Color(150,150,150,0);
public Element getElement()
{
return element;
}
public void start()
{
super.setVisible(false);
}
public void stop()
{
if (alwaysOnTop)
{
setVisible(true);
}
}
public void setVisible(boolean value)
{
if (alwaysOnTop)
{
super.setVisible(true);
if (element.isSelected())
{
setBackground(colorSelected);
}
else
{
setBackground(colorInavtive);
}
}
else
{
super.setVisible(value);
}
}
/** Creates new form SelectionPane */
public SelectionPane(Element element)
{
this.element=element;
initComponents();
setOpaque(false);
setLayout(null);
setBackground(colorSelected);
setLocation(0,0);
setSize(550,550);
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this);
enableEvents(AWTEvent.FOCUS_EVENT_MASK); // catch Focus-Events
enableEvents(AWTEvent.KEY_EVENT_MASK); // catch KeyEvents
enableEvents(AWTEvent.MOUSE_EVENT_MASK); // catch MouseEvents
enableEvents(AWTEvent.COMPONENT_EVENT_MASK); // catch ComponentEvents
}
//--------------------------------------------------------------
@Override
//public boolean isFocusTraversable()
public boolean isFocusable()
{
return true;
}
@Override
protected void processComponentEvent(ComponentEvent event)
{
if (event.getID() == ComponentEvent.COMPONENT_SHOWN)
{
requestFocus();
}
super.processComponentEvent(event);
}
@Override
protected void processFocusEvent(FocusEvent event)
{
if (event.getID() == FocusEvent.FOCUS_GAINED)
{
//hasfocus = true;
//repaint();
}
else if (event.getID() == FocusEvent.FOCUS_LOST)
{
//hasfocus = false;
//repaint();
}
super.processFocusEvent(event);
}
/* protected void processComponentEvent(ComponentEvent co)
{
if (co.getID() == ComponentEvent.COMPONENT_SHOWN) requestFocus();
super.processComponentEvent(co);
}*/
// with that Method you can set Focus when
// the you clicked with Mouse into Canvas!
protected void processMouseEvent(MouseEvent event)
{
if (event.getID() == MouseEvent.MOUSE_PRESSED)
{
requestFocus();
}
super.processMouseEvent(event);
}
// with that Method you can handle your Keys
protected void processKeyEvent(KeyEvent ke)
{
element.processKeyEvent(ke);
// super.processKeyEvent(ke);
}
//--------------------------------------------------------------
public void setAlwaysOnTop(boolean value)
{
alwaysOnTop=value;
if (value)
{
setBackground(colorInavtive);
}
else
{
setBackground(colorSelected);
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
private void paintSelection(Graphics2D g2)
{
//g2.setColor(new Color(100,100,100,128));
/* BufferedImage image=element.owner.owner.selectionImage;
if (image!=null)
{
Rectangle2D tr = new Rectangle2D.Double(0, 0, image.getWidth(), image.getHeight());
TexturePaint tp = new TexturePaint(image, tr);
g2.setPaint(tp);
}*/
g2.fillRect(0,0,getWidth(), getHeight());
}
private int strokeWidth=10;
private Stroke standardStroke=new BasicStroke(strokeWidth);
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
int w=getWidth()-2;
int h=getHeight()-2;
int d=6;
int w2=(w/2)-(d/2);
int h2=(h/2)-(d/2);
//g.setColor(getBackground());
//paintSelection((Graphics2D)g);
g.setColor(getBackground());
paintSelection((Graphics2D)g);
/*if (element.owner.owner.debugMode==false)
{
paintSelection((Graphics2D)g);
} else
{
g2.setStroke(standardStroke);
g.drawRect(strokeWidth,strokeWidth,getWidth()-strokeWidth*2, getHeight()-strokeWidth*2);
}*/
if (element.isSelected() && element.owner.owner.debugMode==false)
{
if (element.isResizeSynchron())
{
drawSelectionPin(g,w-d, h-d,d); // Right-Bottom
}
else
if (element.isResizable())
{
drawSelectionPin(g,0, 0,d); // Left-Top
drawSelectionPin(g,w2, 0,d); // Center-Top
drawSelectionPin(g,w-d, 0,d); // Right-Top
drawSelectionPin(g,0, h2,d); // Left-Center
drawSelectionPin(g,w-d, h2,d); // Right-Center
drawSelectionPin(g,0, h-d,d); // Left-Bottom
drawSelectionPin(g,w2, h-d,d); // Center-Bottom
drawSelectionPin(g,w-d, h-d,d); // Right-Bottom
}
}
}
public void mouseClicked(MouseEvent e)
{
if (element!=null) element.mouseClicked(e);
}
public void mousePressed(MouseEvent e)
{
if (element!=null) element.mousePressed(e);
}
public void mouseReleased(MouseEvent e)
{
if (element!=null) element.mouseReleased(e);
}
public void mouseEntered(MouseEvent e)
{
if (element!=null) element.mouseEntered(e);
}
public void mouseExited(MouseEvent e)
{
if (element!=null) element.mouseExited(e);
}
public void mouseDragged(MouseEvent e)
{
if (element!=null)
{
element.mouseDragged(e);
}
}
public void mouseMoved(MouseEvent e)
{
if (element!=null) element.mouseMoved(e);
}
private void drawSelectionPin(Graphics g,int x, int y, int w)
{
g.setColor(Color.WHITE);
g.fillRect(x, y, w, w);
g.setColor(Color.BLACK);
g.fillRect(x+1, y+1, w-2, w-2);;
}
public void keyTyped(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.