Example usage for java.awt Component getParent

List of usage examples for java.awt Component getParent

Introduction

In this page you can find the example usage for java.awt Component getParent.

Prototype

public Container getParent() 

Source Link

Document

Gets the parent of this component.

Usage

From source file:de.fhg.iais.asc.ui.parts.HarvesterPanel.java

private JTextField createSetsTextField() {
    final JTextField textField = new JTextField(30);

    textField.addFocusListener(new FocusAdapter() {
        @Override/*w  w w .  j  av a2  s  .co m*/
        public void focusGained(FocusEvent e) {
            e.getOppositeComponent().requestFocus();

            // get the frame the panel is embedded in
            Component currentComponent = HarvesterPanel.this;
            while (currentComponent.getParent() != null && !(currentComponent instanceof JFrame)) {
                currentComponent = currentComponent.getParent();
            }
            final JFrame parentFrame = currentComponent instanceof JFrame ? (JFrame) currentComponent : null;

            if (HarvesterPanel.this.availableSets == null) {
                LocalizedOptionPane.showMessageDialog(parentFrame, "No_setnames_retrieved",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            String[] selectedSets = textField.getText().split(","); //$NON-NLS-1$

            for (int i = 0; i < selectedSets.length; i++) {
                selectedSets[i] = selectedSets[i].trim();
            }

            SetSelectionWindow ssw = new SetSelectionWindow(parentFrame, HarvesterPanel.this.availableSets,
                    selectedSets);
            ssw.setVisible(true);

            textField.setText(StringUtils.join(ssw.getSelectedSets(), ", "));
        }
    });

    return textField;
}

From source file:org.zaproxy.zap.extension.httppanel.view.syntaxhighlight.HttpPanelSyntaxHighlightTextArea.java

public void saveConfiguration(String key, FileConfiguration fileConfiguration) {
    fileConfiguration.setProperty(key + ANTI_ALIASING, Boolean.valueOf(this.getAntiAliasingEnabled()));

    Component c = getParent();
    if (c instanceof JViewport) {
        c = c.getParent();
        if (c instanceof RTextScrollPane) {
            final RTextScrollPane scrollPane = (RTextScrollPane) c;
            fileConfiguration.setProperty(key + SHOW_LINE_NUMBERS,
                    Boolean.valueOf(scrollPane.getLineNumbersEnabled()));
        }/*from   w w w.  j a  v a  2s.c  o m*/
    }

    fileConfiguration.setProperty(key + WORD_WRAP, Boolean.valueOf(this.getLineWrap()));

    fileConfiguration.setProperty(key + HIGHLIGHT_CURRENT_LINE,
            Boolean.valueOf(this.getHighlightCurrentLine()));
    fileConfiguration.setProperty(key + FADE_CURRENT_HIGHLIGHT_LINE,
            Boolean.valueOf(this.getFadeCurrentLineHighlight()));

    fileConfiguration.setProperty(key + SHOW_WHITESPACE_CHARACTERS,
            Boolean.valueOf(this.isWhitespaceVisible()));
    fileConfiguration.setProperty(key + SHOW_NEWLINE_CHARACTERS, Boolean.valueOf(this.getEOLMarkersVisible()));

    fileConfiguration.setProperty(key + MARK_OCCURRENCES, Boolean.valueOf(this.getMarkOccurrences()));

    fileConfiguration.setProperty(key + ROUNDED_SELECTION_EDGES,
            Boolean.valueOf(this.getRoundedSelectionEdges()));

    fileConfiguration.setProperty(key + BRACKET_MATCHING, Boolean.valueOf(this.isBracketMatchingEnabled()));
    fileConfiguration.setProperty(key + ANIMATED_BRACKET_MATCHING,
            Boolean.valueOf(this.getAnimateBracketMatching()));
}

From source file:org.zaproxy.zap.extension.httppanel.view.syntaxhighlight.HttpPanelSyntaxHighlightTextArea.java

public void loadConfiguration(String key, FileConfiguration fileConfiguration) {
    setAntiAliasingEnabled(fileConfiguration.getBoolean(key + ANTI_ALIASING, this.getAntiAliasingEnabled()));

    Component c = getParent();
    if (c instanceof JViewport) {
        c = c.getParent();
        if (c instanceof RTextScrollPane) {
            final RTextScrollPane scrollPane = (RTextScrollPane) c;
            scrollPane.setLineNumbersEnabled(
                    fileConfiguration.getBoolean(key + SHOW_LINE_NUMBERS, scrollPane.getLineNumbersEnabled()));
        }//  w  ww  .j a  va  2  s.  c  om
    }

    setLineWrap(fileConfiguration.getBoolean(key + WORD_WRAP, this.getLineWrap()));

    setHighlightCurrentLine(
            fileConfiguration.getBoolean(key + HIGHLIGHT_CURRENT_LINE, this.getHighlightCurrentLine()));
    setFadeCurrentLineHighlight(fileConfiguration.getBoolean(key + FADE_CURRENT_HIGHLIGHT_LINE,
            this.getFadeCurrentLineHighlight()));

    setWhitespaceVisible(
            fileConfiguration.getBoolean(key + SHOW_WHITESPACE_CHARACTERS, this.isWhitespaceVisible()));
    setEOLMarkersVisible(
            fileConfiguration.getBoolean(key + SHOW_NEWLINE_CHARACTERS, this.getEOLMarkersVisible()));

    setMarkOccurrences(fileConfiguration.getBoolean(key + MARK_OCCURRENCES, this.getMarkOccurrences()));

    setRoundedSelectionEdges(
            fileConfiguration.getBoolean(key + ROUNDED_SELECTION_EDGES, this.getRoundedSelectionEdges()));

    setBracketMatchingEnabled(
            fileConfiguration.getBoolean(key + BRACKET_MATCHING, this.isBracketMatchingEnabled()));
    setAnimateBracketMatching(
            fileConfiguration.getBoolean(key + ANIMATED_BRACKET_MATCHING, this.getAnimateBracketMatching()));
}

From source file:de.fhg.iais.asc.ui.parts.HarvesterPanel.java

private void init(final MyCortexModel myCortexModel) {
    // OAI-PMH URL
    this.oaipmhTextField = new JTextField(20);
    this.retrieveInformationButton = LocalizedUI.createButton("Contact_Repository", new ActionListener() {
        @Override//from   w  w w . j  ava2  s. c  o m
        public void actionPerformed(ActionEvent e) {
            MetadataFormatsAndSetNamesRetriever retriever = new MetadataFormatsAndSetNamesRetriever(
                    HarvesterPanel.this.oaipmhTextField.getText(), myCortexModel.getConfig().getASCState(),
                    myCortexModel.getConfig().get(AscConfiguration.OAIPMH_PROXYHOST, ""), //$NON-NLS-1$
                    Integer.valueOf(myCortexModel.getConfig().get(AscConfiguration.OAIPMH_PROXYPORT, 0)));

            String[] metadataformats = retriever.listMetadataFormats();
            HarvesterPanel.this.oaipmhMetadataComboBox.removeAllItems();
            for (String metadataformat : metadataformats) {
                HarvesterPanel.this.oaipmhMetadataComboBox.addItem(metadataformat);
            }

            HarvesterPanel.this.availableSets = retriever.listSets();

            if (metadataformats.length == 0 && HarvesterPanel.this.availableSets == null) {

                // get the frame the panel is embedded in
                Component currentComponent = HarvesterPanel.this;
                while (currentComponent.getParent() != null && !(currentComponent instanceof JFrame)) {
                    currentComponent = currentComponent.getParent();
                }
                final JFrame parentFrame = currentComponent instanceof JFrame ? (JFrame) currentComponent
                        : null;

                LocalizedOptionPane.showMessageDialog(parentFrame, "UnableToContactRepository",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

        }
    });
    this.add("OAI-PMH_URL", this.oaipmhTextField, this.retrieveInformationButton);

    this.oaipmhMetadataComboBox = this.add("Metadata_format", new JComboBox());
    this.oaipmhMetadataComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Object item = HarvesterPanel.this.oaipmhMetadataComboBox.getSelectedItem();
            myCortexModel.setSelectedMetadataFolder(ObjectUtils.toString(item, null));
        }
    });
    this.oaipmhMetadataFormatLabel = this.getLastLabel();

    this.setsTextField = this.add("Sets", createSetsTextField());

    this.harvestingStrategyComboBox = this.add("Harvesting_Strategy", new JComboBox(HARVEST_STRATEGIES));
    this.harvestingStrategyComboBox.setSelectedIndex(0);

    this.fromDateTextField = this.add("From_date", new DatePickerJTextField());

    this.untilDateTextField = this.add("Until_date", new DatePickerJTextField());

    this.inboxfolder = myCortexModel.getConfig().get(INBOX,
            MyCortex.DEFAULT_REPOSITORY_LOCATION + "/asc/inbox"); //$NON-NLS-1$
    this.outboxfolder = myCortexModel.getConfig().get(OUTBOX,
            MyCortex.DEFAULT_REPOSITORY_LOCATION + "/asc/outbox"); //$NON-NLS-1$
}

From source file:de.fhg.iais.asc.ui.parts.TransformersPanel.java

private JPanel createSelectTransformersRadioGroup() {
    this.localTransformersRadioButton = LocalizedUI.createRadioButton("Transform.UseLocalScripts"); //$NON-NLS-1$
    this.localTransformersRadioButton.setSelected(true);
    this.remoteTransformersRadioButton = LocalizedUI.createRadioButton("Transform.UseRemoteScripts"); //$NON-NLS-1$

    // You've to remove this if the transformer scripts presenting server is enabled.
    this.remoteTransformersRadioButton.setEnabled(false);

    // Group the radio buttons.
    ButtonGroup group = new ButtonGroup();
    group.add(this.localTransformersRadioButton);
    group.add(this.remoteTransformersRadioButton);

    JPanel tranformersInnerPanel = new JPanel(new GridLayout(2, 1));

    this.localTransformersRadioButton.addActionListener(new ActionListener() {
        @Override//  w  ww .  ja v a 2  s.  c om
        public void actionPerformed(ActionEvent e) {
            if (TransformersPanel.this.localTransformersRadioButton.isSelected()) {
                TransformersPanel.this.myCortexModel.getConfig().put(AscConfiguration.TRANSFORMERS_URL,
                        DEFAULT_TRANSFORMER_URL);
            }
        }
    });
    this.remoteTransformersRadioButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (TransformersPanel.this.remoteTransformersRadioButton.isSelected()) {
                // get the frame the panel is embedded in
                Component currentComponent = TransformersPanel.this;
                while (currentComponent.getParent() != null && !(currentComponent instanceof JFrame)) {
                    currentComponent = currentComponent.getParent();
                }
                final JFrame parentFrame = currentComponent instanceof JFrame ? (JFrame) currentComponent
                        : null;

                (new TransformationURLWindow(parentFrame, TransformersPanel.this.myCortexModel.getConfig()))
                        .setVisible(true);
                if (TransformersPanel.this.myCortexModel.getConfig()
                        .get(AscConfiguration.TRANSFORMERS_URL, DEFAULT_TRANSFORMER_URL)
                        .equals(DEFAULT_TRANSFORMER_URL)) {
                    TransformersPanel.this.remoteTransformersRadioButton.setSelected(false);
                    TransformersPanel.this.localTransformersRadioButton.setSelected(true);
                }
            }
        }
    });

    tranformersInnerPanel.add(this.localTransformersRadioButton);
    tranformersInnerPanel.add(this.remoteTransformersRadioButton);
    return tranformersInnerPanel;
}

From source file:org.kepler.gui.popups.LibraryPopupListener.java

/** Handle a double-click action. */
private void handleDoubleClickOutsideKar(TreePath selPath, MouseEvent event) {
    Object ob = selPath.getLastPathComponent();

    if (ob instanceof EntityLibrary) {
        return;//from ww w .j a  va2s  .  c  om
    } else {

        int liid = LibraryManager.getLiidFor((ComponentEntity) ob);
        LibItem li = null;
        try {
            li = LibraryManager.getInstance().getPopulatedLibItem(liid);
        } catch (SQLException e) {
            MessageHandler.error("Error accessinc library item.", e);
            return;
        }

        // open it if it's a MoML
        String filePath = li.getAttributeValue(LibIndex.ATT_XMLFILE);
        if (filePath != null) {
            Component component = _aptree.getParentComponent();
            while (component != null && !(component instanceof TableauFrame)) {
                component = component.getParent();
            }
            if (component == null) {
                MessageHandler.error("Could not find TableauFrame.");
                return;
            }
            Configuration configuration = ((TableauFrame) component).getConfiguration();
            try {
                URL url = new File(filePath).toURI().toURL();
                configuration.openModel(url, url, url.toExternalForm());
            } catch (Exception e) {
                MessageHandler.error("Error opening " + filePath, e);
            }

            // if we successfully opened a file, update the history menu and
            // set the last directory.

            // update the history menu
            if (component instanceof KeplerGraphFrame) {
                try {
                    ((KeplerGraphFrame) component).updateHistory(filePath);
                } catch (IOException exception) {
                    MessageHandler.error("Unable to update history menu.", exception);
                }
            }
            if (component instanceof BasicGraphFrame) {
                ((BasicGraphFrame) component).setLastDirectory(new File(filePath).getParentFile());
            }

        } else if (li.getLsid() != null) {
            // if it has an lsid, show the documentation
            Component component = _aptree.getParentComponent();
            while (component != null && !(component instanceof PtolemyFrame)) {
                component = component.getParent();
            }
            if (component == null) {
                MessageHandler.error("Could not find TableauFrame.");
                return;
            }
            ShowDocumentationAction action = new ShowDocumentationAction(selPath, _aptree.getParentComponent());
            action.setLsidToView(li.getLsid());
            action.setPtolemyFrame((PtolemyFrame) component);

            action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_FIRST, "open"));
        }
    }
}

From source file:edu.ku.brc.specify.prefs.SystemPrefs.java

/**
 * /*from w  w w.j  a v a  2s  .com*/
 */
protected void clearCache() {
    final String CLEAR_CACHE = "CLEAR_CACHE";
    final JStatusBar statusBar = UIRegistry.getStatusBar();
    statusBar.setIndeterminate(CLEAR_CACHE, true);

    Component dlg = getParent();
    while (dlg != null && !(dlg instanceof JDialog)) {
        dlg = dlg.getParent();
    }
    Point loc = null;
    if (dlg != null) {
        loc = dlg.getLocation();
    }

    final JDialog parentDlg = (JDialog) dlg;

    Rectangle screenRect = dlg.getGraphicsConfiguration().getBounds();
    parentDlg.setLocation(loc.x, screenRect.height);

    javax.swing.SwingWorker<Integer, Integer> backupWorker = new javax.swing.SwingWorker<Integer, Integer>() {
        @Override
        protected Integer doInBackground() throws Exception {
            try {
                long startTm = System.currentTimeMillis();

                Specify.getCacheManager().clearAll();

                // Tell the OK btn a change has occurred and update the OK btn
                FormValidator validator = ((FormViewObj) form).getValidator();
                if (validator != null) {
                    validator.setHasChanged(true);
                    validator.wasValidated(null);
                    validator.dataChanged(null, null, null);
                }

                Thread.sleep(Math.max(0, 2000 - (System.currentTimeMillis() - startTm)));

            } catch (Exception ex) {
            }

            return null;
        }

        @Override
        protected void done() {
            super.done();

            statusBar.setProgressDone(CLEAR_CACHE);

            UIRegistry.clearSimpleGlassPaneMsg();

            UIRegistry.displayLocalizedStatusBarText("SystemPrefs.CACHE_CLEARED");

            UIHelper.centerWindow(parentDlg);
        }
    };

    UIRegistry.writeSimpleGlassPaneMsg(getLocalizedMessage("SystemPrefs.CLEARING_CACHE"), 24);
    backupWorker.execute();
}

From source file:org.jas.dnd.DnDListenerCollection.java

private void addListenersToMotionMap(Class<?> clazz, Component c, DnDListenerEntries<T> result) {
    if (c == null) {
        return;//from  w  ww  .  j a v  a2  s.c o  m
    }
    List<T> list = listeners.get(c);
    if (list != null) {
        for (T t : list) {
            result.put(clazz, c, t);
        }
    }
    addListenersToMotionMap(clazz, c.getParent(), result);
}

From source file:edu.harvard.mcz.imagecapture.ui.ButtonEditor.java

@Override
public void actionPerformed(ActionEvent e) {

    // Action might not be event_button_pressed on all systems.
    log.debug("Button event actionCommand: " + e.getActionCommand());
    if (e.getActionCommand().equals(EVENT_PRESSED)) {
        // Event is a click on the cell
        // Identify the row that was clicked on.
        JTable table = (JTable) ((JButton) e.getSource()).getParent();
        log.debug(e.getSource());//from   w w w .j av a2s  .co  m
        log.debug(table);
        int row = table.getEditingRow();
        // Stop editing - note, we need to have gotten e.getSource.getParent and getEditingRow first.
        fireEditingStopped(); //Make the renderer reappear.
        Singleton.getSingletonInstance().getMainFrame()
                .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        switch (formToOpen) {
        case OPEN_SPECIMEN_DETAILS:
            // Load the selected specimen record from its ID (the data value behind the button).
            //SpecimenLifeCycle sls = new SpecimenLifeCycle();
            //Specimen specimen = sls.findById((Long)targetId);
            //if (specimen!=null) {
            if (targetId != null) {
                // a specimen with this ID exists, bring up the details editor.
                try {
                    //SpecimenControler sc = new SpecimenControler(specimen);
                    if (((Specimen) targetId).getSpecimenId() != null) {
                        if (((Specimen) targetId).isStateDone()) {
                            // Specimens in state_done are no longer editable
                            JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                                    "This Specimen record has been migrated and can no longer be edited here ["
                                            + ((Specimen) targetId).getLoadFlags()
                                            + "].\nSee: http://mczbase.mcz.harvard.edu/guid/MCZ:Ent:"
                                            + ((Specimen) targetId).getCatNum(),
                                    "Migrated Specimen", JOptionPane.WARNING_MESSAGE);
                        } else {
                            // Specimen is still editable
                            if (table != null) {
                                // Pass the specimen object for the row, the table model, and the row number on to the specimen controler.
                                try {
                                    SpecimenControler sc = new SpecimenControler((Specimen) targetId,
                                            (SpecimenListTableModel) table.getModel(), table, row);
                                    if (table.getParent().getParent().getParent().getParent()
                                            .getClass() == SpecimenBrowser.class) {
                                        sc.addListener((DataChangeListener) table.getParent());
                                    } else {
                                        Component x = table;
                                        boolean done = false;
                                        while (!done) {
                                            log.debug(x.getParent());
                                            x = x.getParent();
                                            if (x.getClass() == SpecimenBrowser.class) {
                                                sc.addListener((DataChangeListener) x);
                                                done = true;
                                            }
                                        }
                                    }
                                    sc.displayInEditor();
                                } catch (java.lang.ClassCastException eNotSp) {
                                    // Request isn't coming from a SpecimenListTableModel
                                    // View just the specimen record.
                                    SpecimenControler sc = new SpecimenControler((Specimen) targetId);
                                    sc.displayInEditor();
                                }
                            } else {
                                log.debug(e.getSource());
                                //SpecimenControler sc = new SpecimenControler((Specimen)targetId);
                                //sc.displayInEditor();
                            }
                        }
                    } else {
                        log.debug("User clicked on table row containing a new Specimen()");
                        JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                                "No Specimen for this image", "Load Specimen Failed",
                                JOptionPane.WARNING_MESSAGE);
                    }
                } catch (NoSuchRecordException e1) {
                    log.error("Tested for specimen!=null, but SpecimenControler threw null specimen exception");
                    log.error(e1);
                }
            } else {
                log.debug("No matches found to specimen id=" + targetId);
                // TODO: Create new specimen record and bring up dialog
                JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                        "No specimen record.");
            }
            break;
        case OPEN_TEMPLATE:
            // Load the selected specimen record from its ID (the data value behind the button).
            try {
                // a template with this targetID exists, display it.
                ((PositionTemplateEditor) parentComponent).setTemplate((String) targetId);
            } catch (NoSuchTemplateException e1) {
                log.error("No such template on button press on a template in list.");
                log.error(e1);
                log.trace(e1);
            }

            break;
        case OPEN_USER:
            //TODO: tie to user
            log.debug("Open user");
            ((UserListBrowser) parentComponent).getEditUserPanel().setUser((Users) targetId);
            break;
        case OPEN_SPECIMEN_VERBATIM:
            log.debug("Open Verbatim Transcription");
            SpecimenLifeCycle sls = new SpecimenLifeCycle();
            List<Specimen> toTranscribe = sls.findForVerbatim(((GenusSpeciesCount) targetId).getGenus(),
                    ((GenusSpeciesCount) targetId).getSpecificEpithet(), WorkFlowStatus.STAGE_1);
            log.debug(toTranscribe.size());
            SpecimenListTableModel stm = new SpecimenListTableModel(toTranscribe);
            JTable stable = new JTable();
            stable.setModel(stm);
            SpecimenControler verbCont;
            try {
                verbCont = new SpecimenControler(toTranscribe.get(0), stm, stable, 0);
                VerbatimCaptureDialog dialog = new VerbatimCaptureDialog(toTranscribe.get(0), verbCont);
                dialog.setVisible(true);
            } catch (NoSuchRecordException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            break;
        case OPEN_VERBATIM_CLASSIFY:
            log.debug("Open Verbatim Classify dialog");
            try {
                VerbatimClassifyDialog dialog = new VerbatimClassifyDialog(
                        (VerbatimCount) table.getModel().getValueAt(row, 0));
                dialog.setVisible(true);
            } catch (ClassCastException e1) {
                log.error(e1.getMessage(), e1);
            }
            break;
        case ACTION_CANCEL_JOB:
            log.debug("Action Cancel requested on job " + targetId);
            Singleton.getSingletonInstance().getJobList().getJobAt((Integer) targetId).cancel();
            break;
        case OPEN_SPECIMENPARTATTRIBUTES:
            SpecimenPartAttributeDialog attrDialog = new SpecimenPartAttributeDialog((SpecimenPart) targetId);
            attrDialog.setVisible(true);
            break;
        }
        Singleton.getSingletonInstance().getMainFrame()
                .setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        System.gc();
    }
}

From source file:org.jas.dnd.MultiLayerDropTargetListener.java

@Override
public void dragEnter(DropTargetDragEvent dtde) {
    getDragAction().dragExit();/*from  ww  w .j  ava2s  .  c  o  m*/
    lastDropSuccess = false;
    Window window = null;
    Component component;
    Component component2 = component = dtde.getDropTargetContext().getComponent();
    while (window == null && component != null) {
        if (component instanceof Window) {
            window = (Window) component;
        } else {
            component = component.getParent();
        }
    }
    Container currentTriggerFrame = null;
    if (window == null) {
        if (component2 instanceof Container) {
            currentTriggerFrame = (Container) component2;
        } else {
            currentTriggerFrame = component2.getParent();
        }
    } else {
        currentTriggerFrame = window;
    }
    getDragAction(currentTriggerFrame);
    dragOver(dtde);
}