Lines 52-58
Link Here
|
52 |
import org.netbeans.core.windows.Constants; |
52 |
import org.netbeans.core.windows.Constants; |
53 |
import org.netbeans.core.windows.Debug; |
53 |
import org.netbeans.core.windows.Debug; |
54 |
import org.netbeans.core.windows.WindowManagerImpl; |
54 |
import org.netbeans.core.windows.WindowManagerImpl; |
55 |
import org.netbeans.core.windows.view.ui.Tabbed; |
55 |
import org.netbeans.swing.tabcontrol.customtabs.Tabbed; |
56 |
import org.netbeans.swing.tabcontrol.ComponentConverter; |
56 |
import org.netbeans.swing.tabcontrol.ComponentConverter; |
57 |
import org.netbeans.swing.tabcontrol.TabData; |
57 |
import org.netbeans.swing.tabcontrol.TabData; |
58 |
import org.netbeans.swing.tabcontrol.TabbedContainer; |
58 |
import org.netbeans.swing.tabcontrol.TabbedContainer; |
Lines 64-75
Link Here
|
64 |
import javax.swing.event.ChangeEvent; |
64 |
import javax.swing.event.ChangeEvent; |
65 |
import javax.swing.event.ChangeListener; |
65 |
import javax.swing.event.ChangeListener; |
66 |
import java.awt.*; |
66 |
import java.awt.*; |
67 |
import java.util.ArrayList; |
67 |
import java.awt.event.ActionListener; |
68 |
import java.util.Arrays; |
68 |
import java.util.Arrays; |
69 |
import org.netbeans.core.windows.ModeImpl; |
69 |
import org.netbeans.core.windows.ModeImpl; |
70 |
import org.netbeans.core.windows.Switches; |
70 |
import org.netbeans.core.windows.Switches; |
71 |
import org.netbeans.core.windows.actions.ActionUtils; |
71 |
import org.netbeans.core.windows.actions.ActionUtils; |
72 |
import org.netbeans.core.windows.view.dnd.TopComponentDraggable; |
|
|
73 |
import org.netbeans.swing.tabcontrol.TabDisplayer; |
72 |
import org.netbeans.swing.tabcontrol.TabDisplayer; |
74 |
import org.netbeans.swing.tabcontrol.WinsysInfoForTabbedContainer; |
73 |
import org.netbeans.swing.tabcontrol.WinsysInfoForTabbedContainer; |
75 |
import org.netbeans.swing.tabcontrol.event.TabActionEvent; |
74 |
import org.netbeans.swing.tabcontrol.event.TabActionEvent; |
Lines 81-87
Link Here
|
81 |
* |
80 |
* |
82 |
* @author Tim Boudreau |
81 |
* @author Tim Boudreau |
83 |
*/ |
82 |
*/ |
84 |
public class TabbedAdapter extends TabbedContainer implements Tabbed, Tabbed.Accessor, SlideController { |
83 |
public class TabbedAdapter extends TabbedContainer implements Tabbed.Accessor, SlideController { |
85 |
|
84 |
|
86 |
public static final int DOCUMENT = 1; |
85 |
public static final int DOCUMENT = 1; |
87 |
|
86 |
|
Lines 93-100
Link Here
|
93 |
private PropertyChangeListener tooltipListener, weakTooltipListener; |
92 |
private PropertyChangeListener tooltipListener, weakTooltipListener; |
94 |
|
93 |
|
95 |
/** Creates a new instance of TabbedAdapter */ |
94 |
/** Creates a new instance of TabbedAdapter */ |
96 |
public TabbedAdapter (int type) { |
95 |
public TabbedAdapter (int type, WinsysInfoForTabbedContainer winsysInfo) { |
97 |
super (null, type, new WinsysInfo(type)); |
96 |
super (null, type, winsysInfo); |
98 |
getSelectionModel().addChangeListener(new ChangeListener() { |
97 |
getSelectionModel().addChangeListener(new ChangeListener() { |
99 |
@Override |
98 |
@Override |
100 |
public void stateChanged (ChangeEvent ce) { |
99 |
public void stateChanged (ChangeEvent ce) { |
Lines 104-201
Link Here
|
104 |
} |
103 |
} |
105 |
} |
104 |
} |
106 |
}); |
105 |
}); |
107 |
// Color fillC = (Color)UIManager.get("nb_workplace_fill"); //NOI18N |
|
|
108 |
// if (fillC != null) setBackground (fillC); |
109 |
} |
106 |
} |
110 |
|
107 |
|
111 |
@Override |
|
|
112 |
public void addTopComponent(String name, javax.swing.Icon icon, TopComponent tc, String toolTip) { |
113 |
insertComponent (name, icon, tc, toolTip, getTabCount()); |
114 |
} |
115 |
|
116 |
@Override |
117 |
public TopComponent getTopComponentAt(int index) { |
118 |
if (index == -1 || index >= getModel().size()) { |
119 |
return null; |
120 |
} |
121 |
return (TopComponent)getModel().getTab(index).getComponent(); |
122 |
} |
123 |
|
124 |
@Override |
125 |
public TopComponent getSelectedTopComponent() { |
126 |
int i = getSelectionModel().getSelectedIndex(); |
127 |
return i == -1 ? null : getTopComponentAt(i); |
128 |
} |
129 |
|
130 |
@Override |
131 |
public void requestAttention (TopComponent tc) { |
132 |
int idx = indexOf(tc); |
133 |
if (idx >= 0) { |
134 |
requestAttention(idx); |
135 |
} else { |
136 |
Logger.getAnonymousLogger().fine( |
137 |
"RequestAttention on component unknown to container: " + tc); //NOI18N |
138 |
} |
139 |
} |
140 |
|
141 |
@Override |
142 |
public void cancelRequestAttention (TopComponent tc) { |
143 |
int idx = indexOf(tc); |
144 |
if (idx >= 0) { |
145 |
cancelRequestAttention(idx); |
146 |
} else { |
147 |
throw new IllegalArgumentException ("TopComponent " + tc |
148 |
+ " is not a child of this container"); //NOI18N |
149 |
} |
150 |
} |
151 |
|
152 |
@Override |
153 |
public void insertComponent(String name, javax.swing.Icon icon, Component comp, String toolTip, int position) { |
154 |
TabData td = new TabData (comp, icon, name, toolTip); |
155 |
|
156 |
if(DEBUG) { |
157 |
debugLog("InsertTab: " + name + " hash:" + System.identityHashCode(comp)); // NOI18N |
158 |
} |
159 |
|
160 |
getModel().addTab(position, td); |
161 |
comp.addPropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(comp)); |
162 |
} |
163 |
|
164 |
@Override |
165 |
public void setSelectedComponent(Component comp) { |
166 |
int i = indexOf (comp); |
167 |
if (i == -1 && null != comp) { |
168 |
throw new IllegalArgumentException ( |
169 |
"Component not a child of this control: " + comp); //NOI18N |
170 |
} else { |
171 |
getSelectionModel().setSelectedIndex(i); |
172 |
} |
173 |
} |
174 |
|
175 |
@Override |
176 |
public TopComponent[] getTopComponents() { |
177 |
ComponentConverter cc = getComponentConverter(); |
178 |
TabData[] td = (TabData[]) getModel().getTabs().toArray(new TabData[0]); |
179 |
TopComponent[] result = new TopComponent[getModel().size()]; |
180 |
for (int i=0; i < td.length; i++) { |
181 |
result[i] = (TopComponent) cc.getComponent(td[i]); |
182 |
} |
183 |
return result; |
184 |
} |
185 |
|
186 |
@Override |
187 |
public void removeComponent(Component comp) { |
188 |
int i=indexOf(comp); |
189 |
getModel().removeTab(i); |
190 |
comp.removePropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(comp)); |
191 |
if (getModel().size() == 0) { |
192 |
revalidate(); |
193 |
repaint(); |
194 |
} |
195 |
} |
196 |
|
108 |
|
197 |
public void addComponents(Component[] comps, String[] names, javax.swing.Icon[] icons, String[] tips) { |
109 |
public void addComponents(Component[] comps, String[] names, javax.swing.Icon[] icons, String[] tips) { |
198 |
ArrayList al = new ArrayList (comps.length); |
|
|
199 |
TabData[] data = new TabData[comps.length]; |
110 |
TabData[] data = new TabData[comps.length]; |
200 |
for (int i=0; i < comps.length; i++) { |
111 |
for (int i=0; i < comps.length; i++) { |
201 |
TabData td = new TabData (comps[i], icons[i], names[i], tips[i]); |
112 |
TabData td = new TabData (comps[i], icons[i], names[i], tips[i]); |
Lines 205-269
Link Here
|
205 |
getModel().addTabs (0, data); |
116 |
getModel().addTabs (0, data); |
206 |
} |
117 |
} |
207 |
|
118 |
|
208 |
@Override |
|
|
209 |
public void setTopComponents(TopComponent[] tcs, TopComponent selected) { |
210 |
// #100144 - correct null selection and log, probably some problem in |
211 |
// winsys model consistency, but without reproduction no chance to find out |
212 |
if (selected == null && tcs.length > 0) { |
213 |
selected = tcs[0]; |
214 |
Logger.getLogger(TabbedAdapter.class.getName()).warning( |
215 |
"Selected component is null although open components are " + |
216 |
Arrays.asList(tcs)); |
217 |
} |
218 |
int sizeBefore = getModel().size(); |
219 |
|
220 |
detachTooltipListeners(getModel().getTabs()); |
221 |
|
222 |
TabData[] data = new TabData[tcs.length]; |
223 |
int toSelect=-1; |
224 |
for(int i = 0; i < tcs.length; i++) { |
225 |
TopComponent tc = tcs[i]; |
226 |
Image icon = tc.getIcon(); |
227 |
String displayName = WindowManagerImpl.getInstance().getTopComponentDisplayName(tc); |
228 |
data[i] = new TabData( |
229 |
tc, |
230 |
icon == null ? null : new ImageIcon(icon), |
231 |
displayName == null ? "" : displayName, // NOI18N |
232 |
tc.getToolTipText()); |
233 |
if (selected == tcs[i]) { |
234 |
toSelect = i; |
235 |
} |
236 |
tc.addPropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(tc)); |
237 |
} |
238 |
|
239 |
//DO NOT DELETE THIS ASSERTION AGAIN! |
240 |
//If it triggered, it means there is a problem in the state of the |
241 |
//window system's model. If it is just diagnostic logging, there |
242 |
//*will* be an exception later, it just won't contain any useful |
243 |
//information. See issue 39914 for what happens if it is deleted. |
244 |
assert selected != null && toSelect != -1 : "Tried to set a selected component that was " + |
245 |
" not in the array of open components. ToSelect: " + selected + " ToSelectName=" + selected.getDisplayName() + |
246 |
" ToSelectClass=" + selected.getClass() + |
247 |
" open components: " + Arrays.asList(tcs); |
248 |
|
249 |
getModel().setTabs(data); |
250 |
|
251 |
if (toSelect != -1) { |
252 |
getSelectionModel().setSelectedIndex(toSelect); |
253 |
} else if (selected != null) { |
254 |
//Assertions are off |
255 |
Logger.getAnonymousLogger().warning("Tried to" + |
256 |
"set a selected component that was not in the array of open " + |
257 |
"components. ToSelect: " + selected + " components: " + |
258 |
Arrays.asList(tcs)); |
259 |
} |
260 |
int sizeNow = getModel().size(); |
261 |
if (sizeBefore != 0 && sizeNow == 0) { |
262 |
//issue 40076, ensure repaint if the control has been emptied. |
263 |
revalidate(); |
264 |
repaint(); |
265 |
} |
266 |
} |
267 |
|
119 |
|
268 |
/** Removes tooltip listeners from given tabs */ |
120 |
/** Removes tooltip listeners from given tabs */ |
269 |
private void detachTooltipListeners(List tabs) { |
121 |
private void detachTooltipListeners(List tabs) { |
Lines 275-361
Link Here
|
275 |
} |
127 |
} |
276 |
} |
128 |
} |
277 |
|
129 |
|
278 |
// DnD>> |
|
|
279 |
/** Finds tab which contains x coordinate of given location point. |
280 |
* @param location The point for which a constraint is required |
281 |
* @return Integer object representing found tab index. Returns null if |
282 |
* no such tab can be found. |
283 |
*/ |
284 |
@Override |
285 |
public Object getConstraintForLocation(Point location, boolean attachingPossible) { |
286 |
//#47909 |
287 |
// first process the tabs when mouse is inside the tabs area.. |
288 |
int tab = tabForCoordinate(location); |
289 |
if (tab != -1) { |
290 |
int index = dropIndexOfPoint(location); |
291 |
return index < 0 ? null : Integer.valueOf(index); |
292 |
} |
293 |
// ---- |
294 |
if(attachingPossible) { |
295 |
String s = getSideForLocation(location); |
296 |
if(s != null) { |
297 |
return s; |
298 |
} |
299 |
} |
300 |
int index = dropIndexOfPoint(location); |
301 |
return index < 0 ? null : Integer.valueOf(index); |
302 |
} |
303 |
|
304 |
/** Computes and returns feedback indication shape for given location |
305 |
* point. |
306 |
* TBD - extend for various feedback types |
307 |
* @return Shape representing feedback indication |
308 |
*/ |
309 |
@Override |
310 |
public Shape getIndicationForLocation(Point location, |
311 |
TopComponentDraggable startingTransfer, Point startingPoint, boolean attachingPossible) { |
312 |
|
313 |
Rectangle rect = getBounds(); |
314 |
rect.setLocation(0, 0); |
315 |
|
316 |
TopComponent draggedTC = startingTransfer.getTopComponent(); |
317 |
//#47909 |
318 |
int tab = tabForCoordinate(location); |
319 |
// first process the tabs when mouse is inside the tabs area.. |
320 |
// need to process before the side resolution. |
321 |
if (tab != -1) { |
322 |
Shape s = getDropIndication(draggedTC, location); |
323 |
if(s != null) { |
324 |
return s; |
325 |
} |
326 |
} |
327 |
|
328 |
String side; |
329 |
if(attachingPossible) { |
330 |
side = getSideForLocation(location); |
331 |
} else { |
332 |
side = null; |
333 |
} |
334 |
|
335 |
double ratio = Constants.DROP_TO_SIDE_RATIO; |
336 |
if(side == Constants.TOP) { |
337 |
return new Rectangle(0, 0, rect.width, (int)(rect.height * ratio)); |
338 |
} else if(side == Constants.LEFT) { |
339 |
return new Rectangle(0, 0, (int)(rect.width * ratio), rect.height); |
340 |
} else if(side == Constants.RIGHT) { |
341 |
return new Rectangle(rect.width - (int)(rect.width * ratio), 0, (int)(rect.width * ratio), rect.height); |
342 |
} else if(side == Constants.BOTTOM) { |
343 |
return new Rectangle(0, rect.height - (int)(rect.height * ratio), rect.width, (int)(rect.height * ratio)); |
344 |
} |
345 |
|
346 |
// #47909 now check shape again.. when no sides were checked, assume changing tabs when in component center. |
347 |
Shape s = getDropIndication(draggedTC, location); |
348 |
if(s != null) { |
349 |
return s; |
350 |
} |
351 |
|
352 |
if( startingTransfer.isTopComponentTransfer() && startingPoint != null |
353 |
&& indexOf(startingTransfer.getTopComponent()) != -1) { |
354 |
return getStartingIndication(startingPoint, location); |
355 |
} |
356 |
|
357 |
return rect; |
358 |
} |
359 |
|
130 |
|
360 |
private String getSideForLocation(Point location) { |
131 |
private String getSideForLocation(Point location) { |
361 |
Rectangle bounds = getBounds(); |
132 |
Rectangle bounds = getBounds(); |
Lines 420-443
Link Here
|
420 |
// DnD<< |
191 |
// DnD<< |
421 |
|
192 |
|
422 |
|
193 |
|
423 |
/** Registers ChangeListener to receive events. |
|
|
424 |
* @param listener The listener to register. |
425 |
* |
426 |
*/ |
427 |
@Override |
428 |
public void addChangeListener(ChangeListener listener) { |
429 |
cs.addChangeListener(listener); |
430 |
} |
431 |
|
432 |
/** Removes ChangeListener from the list of listeners. |
433 |
* @param listener The listener to remove. |
434 |
* |
435 |
*/ |
436 |
@Override |
437 |
public void removeChangeListener(ChangeListener listener) { |
438 |
cs.removeChangeListener(listener); |
439 |
} |
440 |
|
441 |
/** Notifies all registered listeners about the event. */ |
194 |
/** Notifies all registered listeners about the event. */ |
442 |
private void fireStateChanged() { |
195 |
private void fireStateChanged() { |
443 |
if (!SwingUtilities.isEventDispatchThread()) { |
196 |
if (!SwingUtilities.isEventDispatchThread()) { |
Lines 472-496
Link Here
|
472 |
Debug.log(TabbedAdapter.class, message); |
225 |
Debug.log(TabbedAdapter.class, message); |
473 |
} |
226 |
} |
474 |
|
227 |
|
475 |
@Override |
|
|
476 |
public Component getComponent() { |
477 |
return this; |
478 |
} |
479 |
|
480 |
/** Add action for enabling auto hide of views */ |
481 |
@Override |
482 |
public Action[] getPopupActions(Action[] defaultActions, int tabIndex) { |
483 |
if( tabIndex < 0 ) { |
484 |
ModeImpl mode = getModeImpl(); |
485 |
if( null != mode ) |
486 |
return ActionUtils.createDefaultPopupActions( mode ); |
487 |
return null; |
488 |
} |
489 |
return defaultActions; |
490 |
} |
491 |
|
492 |
private ModeImpl getModeImpl() { |
228 |
private ModeImpl getModeImpl() { |
493 |
TopComponent[] topComponents = getTopComponents(); |
229 |
TopComponent[] topComponents = tabbedImpl.getTopComponents(); |
494 |
if( topComponents.length < 1 ) |
230 |
if( topComponents.length < 1 ) |
495 |
return null; |
231 |
return null; |
496 |
return ( ModeImpl ) WindowManagerImpl.getInstance().findMode( topComponents[0] ); |
232 |
return ( ModeImpl ) WindowManagerImpl.getInstance().findMode( topComponents[0] ); |
Lines 525-546
Link Here
|
525 |
|
261 |
|
526 |
@Override |
262 |
@Override |
527 |
public Tabbed getTabbed() { |
263 |
public Tabbed getTabbed() { |
528 |
return this; |
264 |
return tabbedImpl; |
529 |
} |
|
|
530 |
|
531 |
@Override |
532 |
public Rectangle getTabBounds(int tabIndex) { |
533 |
return getTabRect(tabIndex, new Rectangle()); |
534 |
} |
535 |
|
536 |
@Override |
537 |
public Rectangle getTabsArea() { |
538 |
return getUI().getTabsArea(); |
539 |
} |
265 |
} |
540 |
|
266 |
|
541 |
/********* implementation of WinsysInfoForTabbed ********/ |
267 |
/********* implementation of WinsysInfoForTabbed ********/ |
542 |
|
268 |
|
543 |
static class WinsysInfo extends WinsysInfoForTabbedContainer { |
269 |
public static class WinsysInfo extends WinsysInfoForTabbedContainer { |
544 |
private int containerType; |
270 |
private int containerType; |
545 |
public WinsysInfo( int containerType ) { |
271 |
public WinsysInfo( int containerType ) { |
546 |
this.containerType = containerType; |
272 |
this.containerType = containerType; |
Lines 628-633
Link Here
|
628 |
} |
354 |
} |
629 |
return weakTooltipListener; |
355 |
return weakTooltipListener; |
630 |
} |
356 |
} |
|
|
357 |
|
358 |
private final Tabbed tabbedImpl = new Tabbed() { |
359 |
|
360 |
@Override |
361 |
public void addTopComponent(String name, javax.swing.Icon icon, TopComponent tc, String toolTip) { |
362 |
insertComponent (name, icon, tc, toolTip, getTabCount()); |
363 |
} |
364 |
|
365 |
@Override |
366 |
public TopComponent getTopComponentAt(int index) { |
367 |
if (index == -1 || index >= getModel().size()) { |
368 |
return null; |
369 |
} |
370 |
return (TopComponent)getModel().getTab(index).getComponent(); |
371 |
} |
372 |
|
373 |
@Override |
374 |
public TopComponent getSelectedTopComponent() { |
375 |
int i = getSelectionModel().getSelectedIndex(); |
376 |
return i == -1 ? null : getTopComponentAt(i); |
377 |
} |
378 |
|
379 |
@Override |
380 |
public void requestAttention (TopComponent tc) { |
381 |
int idx = indexOf(tc); |
382 |
if (idx >= 0) { |
383 |
TabbedAdapter.this.requestAttention(idx); |
384 |
} else { |
385 |
Logger.getAnonymousLogger().fine( |
386 |
"RequestAttention on component unknown to container: " + tc); //NOI18N |
387 |
} |
388 |
} |
389 |
|
390 |
@Override |
391 |
public void cancelRequestAttention (TopComponent tc) { |
392 |
int idx = indexOf(tc); |
393 |
if (idx >= 0) { |
394 |
TabbedAdapter.this.cancelRequestAttention(idx); |
395 |
} else { |
396 |
throw new IllegalArgumentException ("TopComponent " + tc |
397 |
+ " is not a child of this container"); //NOI18N |
398 |
} |
399 |
} |
400 |
|
401 |
@Override |
402 |
public void insertComponent(String name, javax.swing.Icon icon, Component comp, String toolTip, int position) { |
403 |
TabData td = new TabData (comp, icon, name, toolTip); |
404 |
|
405 |
if(DEBUG) { |
406 |
debugLog("InsertTab: " + name + " hash:" + System.identityHashCode(comp)); // NOI18N |
407 |
} |
408 |
|
409 |
getModel().addTab(position, td); |
410 |
comp.addPropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(comp)); |
411 |
} |
412 |
|
413 |
@Override |
414 |
public void setSelectedComponent(Component comp) { |
415 |
int i = indexOf (comp); |
416 |
if (i == -1 && null != comp) { |
417 |
throw new IllegalArgumentException ( |
418 |
"Component not a child of this control: " + comp); //NOI18N |
419 |
} else { |
420 |
getSelectionModel().setSelectedIndex(i); |
421 |
} |
422 |
} |
423 |
|
424 |
@Override |
425 |
public TopComponent[] getTopComponents() { |
426 |
ComponentConverter cc = getComponentConverter(); |
427 |
TabData[] td = (TabData[]) getModel().getTabs().toArray(new TabData[0]); |
428 |
TopComponent[] result = new TopComponent[getModel().size()]; |
429 |
for (int i=0; i < td.length; i++) { |
430 |
result[i] = (TopComponent) cc.getComponent(td[i]); |
431 |
} |
432 |
return result; |
433 |
} |
434 |
|
435 |
@Override |
436 |
public void removeComponent(Component comp) { |
437 |
int i=indexOf(comp); |
438 |
getModel().removeTab(i); |
439 |
comp.removePropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(comp)); |
440 |
if (getModel().size() == 0) { |
441 |
revalidate(); |
442 |
repaint(); |
443 |
} |
444 |
} |
445 |
|
446 |
@Override |
447 |
public Rectangle getTabBounds(int tabIndex) { |
448 |
return getTabRect(tabIndex, new Rectangle()); |
449 |
} |
450 |
|
451 |
@Override |
452 |
public Rectangle getTabsArea() { |
453 |
return getUI().getTabsArea(); |
454 |
} |
455 |
|
456 |
@Override |
457 |
public void setTopComponents(TopComponent[] tcs, TopComponent selected) { |
458 |
// #100144 - correct null selection and log, probably some problem in |
459 |
// winsys model consistency, but without reproduction no chance to find out |
460 |
if (selected == null && tcs.length > 0) { |
461 |
selected = tcs[0]; |
462 |
Logger.getLogger(TabbedAdapter.class.getName()).warning( |
463 |
"Selected component is null although open components are " + |
464 |
Arrays.asList(tcs)); |
465 |
} |
466 |
int sizeBefore = getModel().size(); |
467 |
|
468 |
detachTooltipListeners(getModel().getTabs()); |
469 |
|
470 |
TabData[] data = new TabData[tcs.length]; |
471 |
int toSelect=-1; |
472 |
for(int i = 0; i < tcs.length; i++) { |
473 |
TopComponent tc = tcs[i]; |
474 |
Image icon = tc.getIcon(); |
475 |
String displayName = WindowManagerImpl.getInstance().getTopComponentDisplayName(tc); |
476 |
data[i] = new TabData( |
477 |
tc, |
478 |
icon == null ? null : new ImageIcon(icon), |
479 |
displayName == null ? "" : displayName, // NOI18N |
480 |
tc.getToolTipText()); |
481 |
if (selected == tcs[i]) { |
482 |
toSelect = i; |
483 |
} |
484 |
tc.addPropertyChangeListener(JComponent.TOOL_TIP_TEXT_KEY, getTooltipListener(tc)); |
485 |
} |
486 |
|
487 |
//DO NOT DELETE THIS ASSERTION AGAIN! |
488 |
//If it triggered, it means there is a problem in the state of the |
489 |
//window system's model. If it is just diagnostic logging, there |
490 |
//*will* be an exception later, it just won't contain any useful |
491 |
//information. See issue 39914 for what happens if it is deleted. |
492 |
assert selected != null && toSelect != -1 : "Tried to set a selected component that was " + |
493 |
" not in the array of open components. ToSelect: " + selected + " ToSelectName=" + selected.getDisplayName() + |
494 |
" ToSelectClass=" + selected.getClass() + |
495 |
" open components: " + Arrays.asList(tcs); |
496 |
|
497 |
getModel().setTabs(data); |
498 |
|
499 |
if (toSelect != -1) { |
500 |
getSelectionModel().setSelectedIndex(toSelect); |
501 |
} else if (selected != null) { |
502 |
//Assertions are off |
503 |
Logger.getAnonymousLogger().warning("Tried to" + |
504 |
"set a selected component that was not in the array of open " + |
505 |
"components. ToSelect: " + selected + " components: " + |
506 |
Arrays.asList(tcs)); |
507 |
} |
508 |
int sizeNow = getModel().size(); |
509 |
if (sizeBefore != 0 && sizeNow == 0) { |
510 |
//issue 40076, ensure repaint if the control has been emptied. |
511 |
revalidate(); |
512 |
repaint(); |
513 |
} |
514 |
} |
515 |
// DnD>> |
516 |
/** Finds tab which contains x coordinate of given location point. |
517 |
* @param location The point for which a constraint is required |
518 |
* @return Integer object representing found tab index. Returns null if |
519 |
* no such tab can be found. |
520 |
*/ |
521 |
@Override |
522 |
public Object getConstraintForLocation(Point location, boolean attachingPossible) { |
523 |
//#47909 |
524 |
// first process the tabs when mouse is inside the tabs area.. |
525 |
int tab = tabForCoordinate(location); |
526 |
if (tab != -1) { |
527 |
int index = dropIndexOfPoint(location); |
528 |
return index < 0 ? null : Integer.valueOf(index); |
529 |
} |
530 |
// ---- |
531 |
if(attachingPossible) { |
532 |
String s = getSideForLocation(location); |
533 |
if(s != null) { |
534 |
return s; |
535 |
} |
536 |
} |
537 |
int index = dropIndexOfPoint(location); |
538 |
return index < 0 ? null : Integer.valueOf(index); |
539 |
} |
540 |
|
541 |
/** Computes and returns feedback indication shape for given location |
542 |
* point. |
543 |
* TBD - extend for various feedback types |
544 |
* @return Shape representing feedback indication |
545 |
*/ |
546 |
@Override |
547 |
public Shape getIndicationForLocation(Point location, |
548 |
TopComponent startingTransfer, Point startingPoint, boolean attachingPossible) { |
549 |
|
550 |
Rectangle rect = getBounds(); |
551 |
rect.setLocation(0, 0); |
552 |
|
553 |
TopComponent draggedTC = startingTransfer; |
554 |
//#47909 |
555 |
int tab = tabForCoordinate(location); |
556 |
// first process the tabs when mouse is inside the tabs area.. |
557 |
// need to process before the side resolution. |
558 |
if (tab != -1) { |
559 |
Shape s = getDropIndication(draggedTC, location); |
560 |
if(s != null) { |
561 |
return s; |
562 |
} |
563 |
} |
564 |
|
565 |
String side; |
566 |
if(attachingPossible) { |
567 |
side = getSideForLocation(location); |
568 |
} else { |
569 |
side = null; |
570 |
} |
571 |
|
572 |
double ratio = Constants.DROP_TO_SIDE_RATIO; |
573 |
if(side == Constants.TOP) { |
574 |
return new Rectangle(0, 0, rect.width, (int)(rect.height * ratio)); |
575 |
} else if(side == Constants.LEFT) { |
576 |
return new Rectangle(0, 0, (int)(rect.width * ratio), rect.height); |
577 |
} else if(side == Constants.RIGHT) { |
578 |
return new Rectangle(rect.width - (int)(rect.width * ratio), 0, (int)(rect.width * ratio), rect.height); |
579 |
} else if(side == Constants.BOTTOM) { |
580 |
return new Rectangle(0, rect.height - (int)(rect.height * ratio), rect.width, (int)(rect.height * ratio)); |
581 |
} |
582 |
|
583 |
// #47909 now check shape again.. when no sides were checked, assume changing tabs when in component center. |
584 |
Shape s = getDropIndication(draggedTC, location); |
585 |
if(s != null) { |
586 |
return s; |
587 |
} |
588 |
|
589 |
if( null != startingTransfer && startingPoint != null |
590 |
&& indexOf(startingTransfer) != -1) { |
591 |
return getStartingIndication(startingPoint, location); |
592 |
} |
593 |
|
594 |
return rect; |
595 |
} |
596 |
|
597 |
@Override |
598 |
public Component getComponent() { |
599 |
return TabbedAdapter.this; |
600 |
} |
601 |
|
602 |
/** Add action for enabling auto hide of views */ |
603 |
@Override |
604 |
public Action[] getPopupActions(Action[] defaultActions, int tabIndex) { |
605 |
if( tabIndex < 0 ) { |
606 |
ModeImpl mode = getModeImpl(); |
607 |
if( null != mode ) |
608 |
return ActionUtils.createDefaultPopupActions( mode ); |
609 |
return null; |
610 |
} |
611 |
return defaultActions; |
612 |
} |
613 |
|
614 |
/** Registers ChangeListener to receive events. |
615 |
* @param listener The listener to register. |
616 |
* |
617 |
*/ |
618 |
@Override |
619 |
public void addChangeListener(ChangeListener listener) { |
620 |
cs.addChangeListener(listener); |
621 |
} |
622 |
|
623 |
/** Removes ChangeListener from the list of listeners. |
624 |
* @param listener The listener to remove. |
625 |
* |
626 |
*/ |
627 |
@Override |
628 |
public void removeChangeListener(ChangeListener listener) { |
629 |
cs.removeChangeListener(listener); |
630 |
} |
631 |
|
632 |
@Override |
633 |
public int getTabCount() { |
634 |
return TabbedAdapter.this.getTabCount(); |
635 |
} |
636 |
|
637 |
@Override |
638 |
public int indexOf( Component tc ) { |
639 |
return TabbedAdapter.this.indexOf( tc ); |
640 |
} |
641 |
|
642 |
@Override |
643 |
public void setTitleAt( int index, String title ) { |
644 |
TabbedAdapter.this.setTitleAt( index, title ); |
645 |
} |
646 |
|
647 |
@Override |
648 |
public void setIconAt( int index, Icon icon ) { |
649 |
TabbedAdapter.this.setIconAt( index, icon ); |
650 |
} |
651 |
|
652 |
@Override |
653 |
public void setToolTipTextAt( int index, String toolTip ) { |
654 |
TabbedAdapter.this.setToolTipTextAt( index, toolTip ); |
655 |
} |
656 |
|
657 |
@Override |
658 |
public void addActionListener( ActionListener al ) { |
659 |
TabbedAdapter.this.addActionListener( al ); |
660 |
} |
661 |
|
662 |
@Override |
663 |
public void removeActionListener( ActionListener al ) { |
664 |
TabbedAdapter.this.removeActionListener( al ); |
665 |
} |
666 |
|
667 |
@Override |
668 |
public void setActive( boolean active ) { |
669 |
TabbedAdapter.this.setActive( active ); |
670 |
} |
671 |
|
672 |
@Override |
673 |
public int tabForCoordinate( Point p ) { |
674 |
return TabbedAdapter.this.tabForCoordinate( p ); |
675 |
} |
676 |
|
677 |
@Override |
678 |
public Image createImageOfTab( int tabIndex ) { |
679 |
return TabbedAdapter.this.createImageOfTab( tabIndex ); |
680 |
} |
681 |
|
682 |
@Override |
683 |
public boolean isTransparent() { |
684 |
return TabbedAdapter.this.isTransparent(); |
685 |
} |
686 |
|
687 |
@Override |
688 |
public void setTransparent( boolean transparent ) { |
689 |
TabbedAdapter.this.setTransparent( transparent ); |
690 |
} |
691 |
|
692 |
}; |
631 |
|
693 |
|
632 |
/** Listening to changes of tooltips of currently asociated top components */ |
694 |
/** Listening to changes of tooltips of currently asociated top components */ |
633 |
private class ToolTipListener implements PropertyChangeListener { |
695 |
private class ToolTipListener implements PropertyChangeListener { |