List of usage examples for javax.swing JComponent getParent
public Container getParent()
From source file:Main.java
static public <T> T getAncestorOfType(JComponent component, Class<T> type) { Container ancestor = component.getParent(); while (ancestor != null) { System.out.println("Check parent : " + ancestor); if (type.isInstance(ancestor)) return (T) ancestor; ancestor = ancestor.getParent(); }/*from w w w .j ava 2s .c o m*/ return null; }
From source file:Main.java
public static void setBoundsAndCenterHorizontally(JComponent component, int x, int y, int width, int height) { Container parent = component.getParent(); int parentWidth = parent.getWidth(); int paddingOnBothSides = parentWidth - width; x = paddingOnBothSides / 2;/*from ww w. j a va 2s.co m*/ component.setBounds(x, y, width, height); }
From source file:Main.java
public static JFrame findParentJFrame(JComponent c) { if (c == null) return null; Component parent = c.getParent(); while (!(parent instanceof JFrame) && (parent != null)) { parent = parent.getParent();/*from w ww . j a v a2 s . c om*/ } return (JFrame) parent; }
From source file:Main.java
public static JTabbedPane findParentJTabbedPane(JComponent c) { if (c == null) return null; Component parent = c.getParent(); while (!(parent instanceof JTabbedPane) && (parent != null)) { parent = parent.getParent();/*w ww . j a v a 2 s .co m*/ } return (JTabbedPane) parent; }
From source file:Main.java
public static boolean isActive(JComponent c) { if (c == null) { return false; }/*from w ww . j a v a 2s .co m*/ boolean active = true; if (c instanceof JInternalFrame) { active = ((JInternalFrame) c).isSelected(); } if (active) { Container parent = c.getParent(); while (parent != null) { if (parent instanceof JInternalFrame) { active = ((JInternalFrame) parent).isSelected(); break; } parent = parent.getParent(); } } if (active) { active = isFrameActive(c); } return active; }
From source file:Main.java
/** * Implements autoscrolling.//ww w .java2 s . com * * @param comp * the component * @param cursorLocn * the cursor location */ public static void defaultAutoScroll(JComponent comp, Point cursorLocn) { Rectangle visible = comp.getVisibleRect(); int x = 0, y = 0, width = 0, height = 0; // Scroll left. if (cursorLocn.x < visible.x + AUTOSCROLL_INSET_SIZE) { x = -SCROLL_AMOUNT; width = SCROLL_AMOUNT; } // Scroll right. else if (cursorLocn.x > visible.x + visible.width - AUTOSCROLL_INSET_SIZE) { x = visible.width + SCROLL_AMOUNT; width = SCROLL_AMOUNT; } // Scroll up. if (cursorLocn.y < visible.y + AUTOSCROLL_INSET_SIZE) { y = -SCROLL_AMOUNT; height = SCROLL_AMOUNT; } // Scroll down. else if (cursorLocn.y > visible.y + visible.height - AUTOSCROLL_INSET_SIZE) { y = visible.height + SCROLL_AMOUNT; height = SCROLL_AMOUNT; } ((JComponent) comp.getParent()).scrollRectToVisible(new Rectangle(x, y, width, height)); }
From source file:com.aw.swing.mvp.binding.component.support.BindingBuilder.java
private void buildBindingFor(Field field, JComponent component) { BindingComponent bindingComponent = null; String fieldName = getFieldName(field.getName()); // todo mejorar el performance de esto // String[] bindingPaths = (String[]) ((JComponent) component.getParent()).getClientProperty(BINDING_PATHS); ParentComponentInfo parentComponentInfo = (ParentComponentInfo) ((JComponent) component.getParent()) .getClientProperty(BINDING_PATHS); String[] bindingPaths = null; if (parentComponentInfo != null) { bindingPaths = parentComponentInfo.getPaths(); }/*from w ww . jav a 2 s. co m*/ String pathFieldName = domainBuilder.builPathFieldName(fieldName, bindingPaths); logger.debug("FieldName <" + fieldName + "> with path <" + pathFieldName + ">"); if (pathFieldName == null) return; if (field.getType() == JCheckBox.class) { bindingComponent = new BndICheckBox(presenter.getBindingMgr().getCurrentInputCmpMgr(), (JCheckBox) component, domainBuilder.getDomain(), pathFieldName); } else if (field.getType() == JTextField.class || field.getType() == JTextArea.class || field.getType() == JTextPane.class || field.getType() == PasswordFieldRectIcon.class || field.getType() == JPasswordField.class) { bindingComponent = new BndIJTextField(presenter.getBindingMgr().getCurrentInputCmpMgr(), (JTextComponent) component, domainBuilder.getDomain(), pathFieldName); presenter.getValidatorMgr().registerBasicRule((BndIJTextField) bindingComponent, ""); } else { throw new IllegalArgumentException("Field JCMP Unknown:" + field.getType()); } if (parentComponentInfo != null && parentComponentInfo.isAllCmpsReadOnly()) { bindingComponent.setAsUIReadOnly(); } bindingComponents.add(bindingComponent); }
From source file:eu.europa.ec.markt.tlmanager.view.binding.BindingManager.java
/** * Determine bean property for a component and sets it up with appropriate listeners. * /*from w w w. ja va2 s .c o m*/ * @param component the component * * @return the bean property */ private BeanProperty setupComponent(final JComponent component) { if (component instanceof JTextField) { final JTextField tf = (JTextField) component; tf.getDocument().addDocumentListener(new DefaultDocumentListener() { @Override protected void changed() { if (component.getParent() instanceof JComboBox) { JComboBox comboBox = (JComboBox) component.getParent(); labelHandler.handleLabelStateFor(comboBox, Util.DEFAULT_NO_SELECTION_ENTRY.equals(tf.getText())); } else { labelHandler.handleLabelStateFor(component, StringUtils.isEmpty(tf.getText())); } labelHandler.handleLabelStateFor(component, tf.getText().isEmpty()); } }); return BP_TEXT; } else if (component instanceof JComboBox) { final JComboBox box = (JComboBox) component; addListenerForEditableCombobox(box, new EditableComboboxListener() { @Override public void itemChanged(Object item) { labelHandler.handleLabelStateFor(component, Util.DEFAULT_NO_SELECTION_ENTRY.equals(item)); } }); return BP_COMBO; } else if (component instanceof MultivaluePanel) { return BP_MVALUE; } else if (component instanceof JXDatePicker) { final JXDatePicker picker = (JXDatePicker) component; picker.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (picker.getDate() != null) { labelHandler.handleLabelStateFor(component, false); } else { labelHandler.handleLabelStateFor(component, true); } } }); return BP_DATEPICKER; } else if (component instanceof DateTimePicker) { final DateTimePicker picker = (DateTimePicker) component; picker.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (picker.getDateTime() != null) { labelHandler.handleLabelStateFor(component, false); } else { labelHandler.handleLabelStateFor(component, true); } } }); return BP_DATETIMEPICKER; } else if (component instanceof JCheckBox) { return BP_CHECKBOX; } else if (component instanceof CertificateProperty) { return BP_CERTIFICATE_PROPERTY; } return null; }
From source file:au.org.ala.delta.editor.DeltaEditor.java
/** * Loads a previously loaded delta file from the Most Recently Used list. It is assumed that the source ActionEvent as set the filename in a client property called "Filename". * //from ww w . ja v a2 s. co m * @param e * The action event that triggered this action * @return A DeltaFileLoader task */ @Action(block = BlockingScope.APPLICATION) public DeltaFileLoader loadPreviousFile(ActionEvent e) { DeltaFileLoader fileOpenTask = null; JComponent item = (JComponent) e.getSource(); if (item != null) { String filename = (String) item.getClientProperty("Filename"); File toOpen = new File(filename); if (toOpen != null && toOpen.exists()) { fileOpenTask = new DeltaFileLoader(this, toOpen); fileOpenTask.addPropertyChangeListener(_statusBar); } else { JOptionPane.showMessageDialog(getMainFrame(), "File not found or not readable!", "File open failed", JOptionPane.ERROR_MESSAGE); item.getParent().remove(item); EditorPreferences.removeFileFromMRU(filename); } } return fileOpenTask; }
From source file:net.sourceforge.squirrel_sql.fw.gui.debug.DebugEventListener.java
private void setToolTipText(JComponent source, AWTEvent event) { Container parent = source.getParent(); String sourceName = source.getName(); String sourceClassName = source.getClass().toString(); String parentClassName = parent == null ? null : parent.getClass().toString(); StringBuilder toolTipText = new StringBuilder(getEventMessagePrefix(event)); if (source instanceof AbstractButton) { toolTipText.append("Button with parentClass="); toolTipText.append(parentClassName); } else {/*from ww w .j a va 2 s. com*/ if (!StringUtils.isEmpty(sourceName)) { toolTipText.append(sourceName); } else if (!StringUtils.isEmpty(sourceClassName)) { toolTipText.append(sourceClassName); } } source.setToolTipText(toolTipText.toString()); }