List of usage examples for java.awt Component getParent
public Container getParent()
From source file:com.projity.pm.graphic.views.GanttView.java
public void init(ReferenceNodeModelCache cache, NodeModel model, CoordinatesConverter coord) { this.coord = coord; this.cache = NodeModelCacheFactory.getInstance().createFilteredCache((ReferenceNodeModelCache) cache, getViewName(), null);// w w w .jav a2s . c om fieldContext = new FieldContext(); fieldContext.setLeftAssociation(true); /*cellStyle=new CellStyle(){ CellFormat cellProperties=new CellFormat(); public CellFormat getCellProperties(GraphicNode node){ cellProperties.setBold(node.isSummary()); cellProperties.setItalic(node.isAssignment()); //cellProperties.setBackground((node.isAssignment())?"NORMAL_LIGHT_YELLOW":"NORMAL_YELLOW"); cellProperties.setCompositeIcon(node.isComposite()); return cellProperties; } };*/ super.init(); updateHeight(project); updateSize(); //sync the height of spreadsheet and gantt leftScrollPane.getViewport().addChangeListener(new ChangeListener() { private Dimension olddl = null; public void stateChanged(ChangeEvent e) { Dimension dl = leftScrollPane.getViewport().getViewSize(); if (dl.equals(olddl)) return; olddl = dl; // Dimension dr=rightScrollPane.getViewport().getViewSize(); // ((Gantt)rightScrollPane.getViewport().getView()).setPreferredSize(new Dimension((int)dr.getWidth(),(int)dl.getHeight())); // rightScrollPane.getViewport().revalidate(); ((Gantt) rightScrollPane.getViewport().getView()).setPreferredSize( new Dimension(rightScrollPane.getViewport().getViewSize().width, dl.height)); } }); //TODO automatic scrolling to add as an option // spreadSheet.getRowHeader().getSelectionModel().addListSelectionListener(new ListSelectionListener(){ // public void valueChanged(ListSelectionEvent e) { // if (!e.getValueIsAdjusting()&&spreadSheet.getRowHeader().getSelectedRowCount()==1){ // List impls=spreadSheet.getSelectedNodesImpl(); // if (impls.size()!=1) return; // Object impl=impls.get(0); // if (!(impl instanceof HasStartAndEnd)) return; // HasStartAndEnd interval=(HasStartAndEnd)impl; // gantt.scrollToTask(interval, true); // } // } // }); MouseWheelListener scrollManager = new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { if (0 != (e.getModifiers() & InputEvent.ALT_MASK)) { Component c = e.getComponent(); while ((c != null) && !(c instanceof JViewport)) c = c.getParent(); JViewport vp = (JViewport) c; Point p = vp.getViewPosition(); int newX = p.x + e.getUnitsToScroll() * getWidth() / 20; if (newX > 0) { p.x = newX; } else { p.x = 0; } vp.setViewPosition(p); } else if (0 != (e.getModifiers() & InputEvent.CTRL_MASK)) { zoom(-e.getUnitsToScroll() / 3); } else { //Vertical scroll allways on gantt chart JViewport vp = (JViewport) gantt.getParent(); Point p = vp.getViewPosition(); int newY = p.y + e.getUnitsToScroll() * gantt.getRowHeight(); if (newY > 0) { p.y = newY; } else { p.y = 0; } vp.setViewPosition(p); } } }; leftScrollPane.getViewport().addMouseWheelListener(scrollManager); gantt.addMouseWheelListener(scrollManager); cache.update(); //Call this last to be sure everything is initialized //gantt.insertCacheData(); //useless? }
From source file:edu.ku.brc.ui.dnd.SimpleGlassPane.java
/** * Receives all key events in the AWT and processes the ones that originated from the current * window with the glass pane./*from w ww . java 2s .c o m*/ * * @param event the AWTEvent that was fired */ public void eventDispatched(AWTEvent event) { //Object source = event.getSource(); boolean srcIsComp = (event.getSource() instanceof Component); if ((event instanceof KeyEvent) && srcIsComp) { if (frame == null) { Component p = getParent(); while (frame == null && p != null) { if (p instanceof JFrame) { frame = (JFrame) p; } p = p.getParent(); } } // If the event originated from the window w/glass pane, consume the event //if ((SwingUtilities.windowForComponent((Component) source) == frame)) { ((KeyEvent) event).consume(); //Toolkit.getDefaultToolkit().beep(); } } }
From source file:org.jas.dnd.DnDListenerCollection.java
public DnDListenerEntries<T> getInmediateEntries(Class<?> clazz, Component component) { DnDListenerEntries<T> entries = new DnDListenerEntries<T>(); if (component == null) { return entries; }//www .ja v a 2s. c o m List<T> listeners = this.listeners.get(component); if (listeners != null) { for (T t : listeners) { entries.put(clazz, component, t); } } if (entries.isEmpty()) { return getInmediateEntries(clazz, component.getParent()); } else { return entries; } }
From source file:savant.controller.FrameController.java
/** * Returns the Frames ordered by their on-screen locations. *///from ww w .j a v a 2 s . c om public Frame[] getOrderedFrames() { Frame[] result = frames.toArray(new Frame[0]); Arrays.sort(result, new Comparator<Component>() { @Override public int compare(Component t, Component t1) { if (t == null) { return t1 == null ? 0 : 1; } else if (t1 == null) { return -1; } int result = t.getY() - t1.getY(); if (result == 0) { result = t.getX() - t1.getX(); } if (result == 0) { result = compare(t.getParent(), t1.getParent()); } return result; } }); return result; }
From source file:org.gcaldaemon.gui.ConfigEditor.java
public final void setServiceEnabled(BooleanEditor editor, boolean enabled) { Component page = editor.getParent(); if (page == null) { if (!enabled) { disabledServices.addLast(editor); }/*from w w w.ja v a 2s . c o m*/ } else { page = page.getParent(); int index = folder.indexOfComponent(page); if (index != -1) { if (enabled) { folder.setForegroundAt(index, Color.BLACK); } else { folder.setForegroundAt(index, Color.GRAY); } } } }
From source file:edu.ku.brc.af.ui.forms.SubViewBtn.java
@Override public void setValue(final Object value, final String defaultValue) { boolean doCloseSession = true; dataObj = value;/*from w ww . jav a 2s.c o m*/ // See if there is a current session boolean hasSession = false; Component comp = getParent(); while (comp != null && !(comp instanceof MultiView)) { comp = comp.getParent(); } FormViewObj fvo = null; if (comp instanceof MultiView) { MultiView mv = (MultiView) comp; fvo = mv.getCurrentViewAsFormViewObj(); hasSession = fvo != null && fvo.getSession() != null; } // Create session if there isn't a session DataProviderSessionIFace sessionLocal = null; try { if (fvo != null) { sessionLocal = fvo.getSession(); doCloseSession = false; } else { sessionLocal = hasSession ? null : DataProviderFactory.getInstance().createSession(); } if (!isSkippingAttach && sessionLocal != null && parentObj != null && parentObj.getId() != null) { // I really really hate doing this: Catch an exception (dirty exception) // and doing nothing, but Hibernate just isn't my friend - 03/26/10 try { sessionLocal.attach(parentObj); } catch (Exception ex) { } } // Retrieve lazy object while in the context of a session (just like a subform would do) if (dataObj != null) { setEnabledInternal(isEnabled()); } updateBtnText(); // note: that by calling this, 'size' gets called and that loads the Set (this must be done). if (dataObj instanceof Set) { cachedSet = new HashSet<Object>(); for (Object obj : (Set<?>) dataObj) { cachedSet.add(obj); } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SubViewBtn.class, ex); ex.printStackTrace(); } finally { if (doCloseSession && sessionLocal != null) { sessionLocal.close(); } } }
From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java
/** * select MenuItem//from w ww . ja v a 2 s .c o m * @param mi JMenuItem */ protected void selectMenuItem(JMenuItem mi) { Component comp = mi; boolean isMenuBarItem = false; String logName = null; while (comp.getParent() != null) { if (comp.getParent() instanceof JPopupMenu) { JPopupMenu jpm = (JPopupMenu) comp.getParent(); comp = jpm.getInvoker(); } else { comp = comp.getParent(); } if (comp instanceof JMenuBar) { isMenuBarItem = true; break; } if (comp instanceof JComponent && !(comp instanceof JMenu)) { break; } } IComponentIdentifier id = null; Action a = new Action(); if (comp instanceof JComponent) { String pth = m_recordHelper.getPath(mi); List parValues = new LinkedList(); parValues.add(pth); parValues.add(Constants.REC_OPERATOR); if (isMenuBarItem) { id = m_recordHelper.getMenuCompID(); a = m_recordHelper.compSysToAction(id, "CompSystem.SelectMenuItem"); //$NON-NLS-1$ } else { try { id = ComponentHandler.getIdentifier(comp); a = m_recordHelper.compSysToAction(id, "CompSystem.PopupSelectByTextPathNew"); //$NON-NLS-1$ logName = createLogicalName(comp, id); parValues.add((new Integer(m_popupMouseBtn)).toString()); } catch (NoIdentifierForComponentException nifce) { // no identifier for the component, log this as an error log.error("no identifier for '" + comp); //$NON-NLS-1$ } } if (logName != null) { createCAP(a, id, parValues, logName); } else { createCAP(a, id, parValues); } } }
From source file:net.mariottini.swing.JFontChooser.java
/** * Show a "Choose Font" dialog with the specified title and modality. * /*from www . ja va 2s . c o m*/ * @param parent * the parent component, or null to use a default root frame as parent. * @param title * the title for the dialog. * @param modal * true to show a modal dialog, false to show a non-modal dialog (in this case the * function will return immediately after making visible the dialog). * @return <code>APPROVE_OPTION</code> if the user chose a font, <code>CANCEL_OPTION</code> if the * user canceled the operation. <code>CANCEL_OPTION</code> is always returned for a * non-modal dialog, use an ActionListener to be notified when the user approves/cancels * the dialog. * @see #APPROVE_OPTION * @see #CANCEL_OPTION * @see #addActionListener */ public int showDialog(Component parent, String title, boolean modal) { final int[] result = new int[] { CANCEL_OPTION }; while (parent != null && !(parent instanceof Window)) { parent = parent.getParent(); } final JDialog d; if (parent instanceof Frame) { d = new JDialog((Frame) parent, title, modal); } else if (parent instanceof Dialog) { d = new JDialog((Dialog) parent, title, modal); } else { d = new JDialog(); d.setTitle(title); d.setModal(modal); } final ActionListener[] listener = new ActionListener[1]; listener[0] = new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(APPROVE_SELECTION)) { result[0] = APPROVE_OPTION; } removeActionListener(listener[0]); d.setContentPane(new JPanel()); d.setVisible(false); d.dispose(); } }; addActionListener(listener[0]); d.setComponentOrientation(getComponentOrientation()); d.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); d.getContentPane().add(this, BorderLayout.CENTER); d.pack(); d.setLocationRelativeTo(parent); d.setVisible(true); return result[0]; }
From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java
/** * creates CAP for Actions Replace Text/* w ww . j a va 2s . c o m*/ * @param source Component */ protected void replaceText(Component source) { Component src = source; Component parent = getComponentParent() != null ? getComponentParent() : src.getParent(); if (parent instanceof JComboBox) { src = parent; } String text = null; boolean isEditable = false; boolean isCbxItem = false; boolean isSupported = true; if (src instanceof JTextComponent) { JTextComponent jtf = (JTextComponent) src; text = jtf.getText(); isEditable = jtf.isEditable(); if ((source instanceof JTextArea || source instanceof JTextPane || source instanceof JEditorPane) && (text.indexOf(CharacterConstants.LINEFEED) != -1 || text.indexOf(CharacterConstants.RETURN) != -1)) { isSupported = false; sendInfoMessage(Constants.REC_MULTILINE_MSG); } if (parent instanceof JTable) { JTable tbl = (JTable) parent; replaceTableText(src, tbl, text); return; } } if (src instanceof JComboBox) { JComboBox cbx = (JComboBox) src; isEditable = cbx.isEditable(); if (isEditable) { ComboBoxEditor cbxEditor = cbx.getEditor(); text = cbxEditor.getItem().toString(); String[] cbxItems = m_recordHelper.getRenderedComboItems(cbx); for (int i = 0; i < cbxItems.length; i++) { String item = cbxItems[i]; if (item.equals(text)) { isCbxItem = true; } } } else { return; } } if (text.length() > Constants.REC_MAX_STRING_LENGTH) { ShowObservInfoMessage infoMsg = new ShowObservInfoMessage(Constants.REC_MAX_STRING_MSG); try { AUTServer.getInstance().getServerCommunicator().send(infoMsg); } catch (CommunicationException e) { // no log available here } return; } if (m_map.get(source) != null && !(text.equals(m_map.get(source).toString())) && isSupported && isEditable && !isCbxItem) { m_map.put(src, text); IComponentIdentifier id = null; try { id = ComponentHandler.getIdentifier(src); Action a = new Action(); a = m_recordHelper.compSysToAction(id, "CompSystem.InputText"); //$NON-NLS-1$ List parameterValues = new LinkedList(); text = StringParsing.singleQuoteText(text); parameterValues.add(text); String logName = createLogicalName(src, id); createCAP(a, id, parameterValues, logName); } catch (NoIdentifierForComponentException nifce) { // no identifier for the component, log this as an error log.error("no identifier for '" + src); //$NON-NLS-1$ } } }
From source file:TableLayout.java
/** * Returns a matrix of Dimension objects specifying the preferred sizes of the * components we are going to layout.//from ww w. j ava 2 s .c o m */ private Dimension[][] getPreferredSizes(Container parent) { int rowCount = rows.size(); Dimension[][] prefSizes = new Dimension[rowCount][columnCount]; for (int i = 0; i < rowCount; i++) { Component[] row = (Component[]) rows.elementAt(i); for (int j = 0; j < columnCount; j++) { Component component = row[j]; // Can only happen on the last line when all the remaining components are null as well if (component == null) break; if (component.getParent() != parent) throw new IllegalStateException("Bad parent specified"); prefSizes[i][j] = component.getPreferredSize(); } } return prefSizes; }