Java Code Examples for java.awt.Component#equals()

The following examples show how to use java.awt.Component#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlideContainer.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@Override
public Component add(Component comp) {
    setsize(comp.getPreferredSize());
    Component[] comps = getComponents();
    if (comps.length > 0) {
        oldComponent = comps[0];
    }
    if (comp.equals(oldComponent)) {
        return super.add(comp);
    }
    if (oldComponent != null) {
        putLayer((JComponent) oldComponent, JLayeredPane.DEFAULT_LAYER);
    }
    Component returnResult = super.add(comp);
    putLayer((JComponent) comp, JLayeredPane.DRAG_LAYER);
    comp.setSize(getPreferredSize());
    comp.setVisible(true);
    comp.setLocation(0, 0 - getPreferredSize().height);
    slideFromTop(comp, oldComponent);
    return returnResult;
}
 
Example 2
Source File: SearchTopicPanel.java    From wandora with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Topic getTopic() throws TopicMapException {
    Component selectedTab = tabbedPane.getSelectedComponent();
    if(selectedTab != null) {
        if(selectedTab.equals(searchContainerPanel)) {
            return searchPanel.getSelectedTopic();
        }
        else if(selectedTab.equals(similarityContainerPanel)) {
            return similarityPanel.getSelectedTopic();
        }
        else if(selectedTab.equals(queryContainerPanel)) {
            return queryPanel.getSelectedTopic();
        }
        else if(selectedTab.equals(tmqlContainerPanel)) {
            return tmqlPanel.getSelectedTopic();
        }
    }
    return openedTopic;
}
 
Example 3
Source File: OperationMouseAdapter.java    From cstc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void mouseReleased(MouseEvent e) {
	startPt = null;

	// no dragging
	if (!window.isVisible() || draggedOperation == null) {
		return;
	}
	int addIndex = -1;

	// get the index of the preview element
	if (currentTargetPanel != null) {
		JPanel operationsPanel = this.currentTargetPanel.getOperationsPanel();
		for (int i = 0; i < operationsPanel.getComponentCount(); i++) {
			Component comp = operationsPanel.getComponent(i);
			if (comp.equals(this.panelPreview)) {
				addIndex = i;
				break;
			}
		}
		// remove preview from panel
		currentTargetPanel.removeComponent(this.panelPreview);
	}
	
	if (addIndex != -1) {
		currentTargetPanel.addComponent(this.draggedOperation, addIndex);
	}
	
	this.draggedOperation = null;
	prevRect = null;
	this.startPt = null;
	this.window.setVisible(false);
	this.currentTargetPanel = null;
}
 
Example 4
Source File: Operation.java    From cstc with GNU General Public License v3.0 5 votes vote down vote up
private void changeFontColor(Container container, Color color) {
	for (Component comp : container.getComponents()) {
		if (comp instanceof JLabel || comp.equals(errorArea)) {
			comp.setForeground(color);
		} else if (comp instanceof Container) {
			changeFontColor((Container) comp, color);
		}
	}
}
 
Example 5
Source File: LoggerHintsCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void enableDisablePanel(boolean enabled) {
    loggersPanel.setEnabled(enabled);
    Component[] components = loggersPanel.getComponents();
    for (Component c : components) {
        if (!c.equals(btnRemove)) {
            c.setEnabled(enabled);
        }
    }
    btnRemove.setEnabled(enabled && !customLoggersList.isEmpty());
    loggersScrollPane.getViewport().getView().setEnabled(enabled);
}
 
Example 6
Source File: Action.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * tests if nodes are all from the same tree
 *
 * @param nodes nodes
 * @throws IllegalArgumentException when given nodes does not pass
 */
protected void testNodes(Node[] nodes) {
    if ((nodes == null) || (nodes.length == 0)) {
        throw new IllegalArgumentException("argument nodes is null or empty");
    }
    Component nodesTree = nodes[0].tree().getSource();
    for (int i = 0; i < nodes.length; i++) {
        if (nodes[i] == null) {
            throw new IllegalArgumentException("argument nodes contains null value");
        }
        if (!nodesTree.equals(nodes[i].tree().getSource())) {
            throw new IllegalArgumentException(nodes[i].toString() + " is from different tree");
        }
    }
}
 
Example 7
Source File: JTabbedPane.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the index of the tab for the specified component.
 * Returns -1 if there is no tab for this component.
 *
 * @param component the component for the tab
 * @return the first tab which matches this component, or -1
 *          if there is no tab for this component
 */
public int indexOfComponent(Component component) {
    for(int i = 0; i < getTabCount(); i++) {
        Component c = getComponentAt(i);
        if ((c != null && c.equals(component)) ||
            (c == null && c == component)) {
            return i;
        }
    }
    return -1;
}
 
Example 8
Source File: Utility.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
public static void enableComponent(Container con, boolean state, Component component) {
	for (Component c : con.getComponents()) {
		if (c instanceof Container) {
			enableComponent((Container) c, state, component);
		}
		if (component != null && component.equals(c)) {
			continue;
		}
		if (c instanceof JLabel) {
			c.setVisible(state);
		} else {
			c.setEnabled(state);
		}
	}
}
 
Example 9
Source File: EncodeDecodeDialog.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private OutputPanelPosition findOutputPanel(JTextComponent searched) {
    for (int i = 0; i < getTabbedPane().getTabCount(); i++) {
        Component tab = getTabbedPane().getComponentAt(i);
        if (tab instanceof JPanel) {
            JPanel parentPanel = (JPanel) tab;
            for (int j = 0; j < parentPanel.getComponentCount(); j++) {
                Component outputPanel = parentPanel.getComponent(j);
                if (outputPanel.equals(searched.getParent().getParent())) {
                    return new OutputPanelPosition(i, j);
                }
            }
        }
    }
    return null;
}
 
Example 10
Source File: RekognitionConfigurationUI.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
private void writeConfiguration(){
    
    RekognitionConfiguration c = null;

    HashMap<AUTH_KEY,String> auth = (configuration.auth == null) ?
            this.getAPIKeys() : configuration.auth;
    
    Component selectedTab = rekognitionTabs.getSelectedComponent();
    if (selectedTab.equals(faceDetectorTab)){
        
        ArrayList<String> jobs = this.getFaceJobs();
        boolean celebrityNaming;
        double celebrityTreshold;
        
        try {
            celebrityNaming = faceAssociateCelebrity.isSelected();
            celebrityTreshold = ((Number)faceCelebrityTreshold.getValue()).floatValue();
        } catch (NumberFormatException e) {
            celebrityNaming = false;
            celebrityTreshold = 0;
        }
        
        c = new RekognitionConfiguration(jobs, celebrityNaming, celebrityTreshold, auth);
        
    }
    
    AbstractRekognitionExtractor.setConfiguration(c);
    
}
 
Example 11
Source File: FBGraphExtractorPanel.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
protected String getObjectId(){
    Component selected = tabPane.getSelectedComponent();
    if(selected.equals(userPanel)){
        return userIdField.getText();
    } else {
        return pageIdField.getText();
    }
}
 
Example 12
Source File: FBGraphExtractorPanel.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
protected Class getObjectClass(){
    Component selected = tabPane.getSelectedComponent();
    if(selected.equals(userPanel)){
        return User.class;
    } else {
        return Page.class;
    }
}
 
Example 13
Source File: OperationMouseAdapter.java    From cstc with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
	Point pt = e.getPoint();
	JComponent parent = (JComponent) e.getComponent();
	
	// not yet dragging and motion > threshold
	if (this.draggedOperation == null && startPt != null) {
		double a = Math.pow(pt.x - startPt.x, 2);
		double b = Math.pow(pt.y - startPt.y, 2);
		if (Math.sqrt(a + b) > gestureMotionThreshold) {
			this.draggedOperation = this.getDraggedOperation(startPt.x, startPt.y);
			if (this.draggedOperation != null) {
				startDragging(pt);
			}
		}
		return;
	}

	// dragging, but no component was created
	if (!window.isVisible() || draggedOperation == null) {
		return;
	}

	pt = SwingUtilities.convertPoint(parent, e.getPoint(), this.target);
	updateWindowLocation(pt, this.target);

	Component targetLine = this.target.getComponentAt(pt);

	// changed the target, remove the old preview
	if (currentTargetPanel != null) {
		if (targetLine == null || !targetLine.equals(currentTargetPanel)) {
			this.currentTargetPanel.removeComponent(panelPreview);
			this.currentTargetPanel = null;
		}
	}

	// we have no valid target
	if (targetLine == null || !(targetLine instanceof RecipeStepPanel)) {
		return;
	}

	RecipeStepPanel targetPanel = (RecipeStepPanel) this.target.getComponentAt(pt);
	this.currentTargetPanel = targetPanel;

	JPanel operationsPanel = currentTargetPanel.getOperationsPanel();
	pt = SwingUtilities.convertPoint(this.target, pt, operationsPanel);

	if (prevRect != null && prevRect.contains(pt)) {
		return;
	}

	boolean gotPreview = false;
	for (int i = 0; i < operationsPanel.getComponentCount(); i++) {
		Component comp = operationsPanel.getComponent(i);
		Rectangle r = comp.getBounds();
		// inside our gap, do nothing
		if (Objects.equals(comp, panelPreview)) {
			if (r.contains(pt)) {
				return;
			} else {
				gotPreview = true;
				continue;
			}
		} 
		
		int tgt;
		if (!(comp instanceof Operation)) { //this is the dummy panel
			int count = operationsPanel.getComponentCount();
			tgt = count > 1 ? operationsPanel.getComponentCount() - 2 : 0;
		} else {
			tgt = getTargetIndex(r, pt, i, gotPreview);				
		}

		if (tgt >= 0) {
			addComponent(currentTargetPanel, panelPreview, tgt);
			return;
		}
	}
}
 
Example 14
Source File: RemotePlatformNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isKnownComponent(Component c) {
    return c.equals(password) || password.isAncestorOf(c);
}
 
Example 15
Source File: MediaWikiAPIExtractorUI.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
public WandoraTool[] getExtractors(MediaWikiAPIExtractor tool) 
        throws Exception {
    
    WandoraTool wt;
    ArrayList<WandoraTool> wts = new ArrayList();
    
    StringBuilder urlBuilder = new StringBuilder();
    String baseUrl, extractUrl;
    String[] qType = new String[2];
    baseUrl = urlField.getText();
    
    boolean crawlClasses = classCrawlToggle.isSelected();

    MediaWikiAPIPageExtractor ex= 
            new MediaWikiAPIPageExtractor(baseUrl, qType, crawlClasses);
    
    //General parameters
    
    urlBuilder.append(baseUrl)
        .append("/api.php?action=query")
        .append("&format=")
        .append(FORMAT)
        .append("&continue="); //For legacy query continue
    
    Component selected = modeTabs.getSelectedComponent();
    
    if(selected.equals(catergoryPanel)){
        
        String category = categoryField.getText();
        if(category.length() > 0){
            qType[0] = "categorymembers";
            qType[1] = "cm";
            urlBuilder.append("&list=categorymembers&cmtitle=");
            if(category.length() < 9 || 
               !category.substring(0, 9).equals("Category:")){
                
                urlBuilder.append("Category:");
            }
            urlBuilder.append(category)
                .append("&cmlimit=")
                .append(LIMIT);
        } else {
            qType[0] = "allpages";
            qType[1] = "ap";
            urlBuilder.append("&list=allpages")
                .append("&aplimit=")
                .append(LIMIT);
        }
        extractUrl = urlBuilder.toString();
        ex.setForceUrls(new String[]{extractUrl});
    } else if(selected.equals(prefixPanel)){
        qType[0] = "allpages";
        qType[1] = "ap";
        urlBuilder.append("&list=allpages")
            .append("&apfrom=")
            .append(prefixField.getText())
            .append("&aplimit=")
            .append(LIMIT);
        
        extractUrl = urlBuilder.toString();
        ex.setForceUrls(new String[]{extractUrl});
    } else if(selected.equals(searchPanel)){
        qType[0] = "search";
        qType[1] = "sr";
        urlBuilder.append("&list=search")
            .append("&srsearch=")
            .append(searchField.getText())
            .append("&srlimit=")
            .append(LIMIT);
        
        extractUrl = urlBuilder.toString();
        ex.setForceUrls(new String[]{extractUrl});
    } else if(selected.equals(titlePanel)){
        ex.setForceContent(titleTextArea.getText());
    } else {
        throw new Exception("Invalid panel!");
    }
    
    ex.setQueryUrl(urlBuilder.toString());
    
    wt = ex;
    wts.add(ex);
    
    return wts.toArray(new WandoraTool[]{});
}
 
Example 16
Source File: SearchTopicPanel.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
private void setCurrentPanel(Component p) {
    if(p != null) {
        if(!p.equals(currentContainerPanel)) {
            
            /*
                Why remove content from other container panels?
                Tabbed pane's height is inherited from the heighest
                component within. Removing content from other container
                panels ensures the tabbed pane inherits it's height from
                the active tab.
            */
            
            if(p.equals(searchContainerPanel)) {
                searchContainerPanel.add(searchPanel, BorderLayout.CENTER);
                similarityContainerPanel.removeAll();
                queryContainerPanel.removeAll();
                tmqlContainerPanel.removeAll();
            }
            else if(p.equals(similarityContainerPanel)) {
                similarityContainerPanel.add(similarityPanel, BorderLayout.CENTER);
                searchContainerPanel.removeAll();
                queryContainerPanel.removeAll();
                tmqlContainerPanel.removeAll();
            }
            else if(p.equals(queryContainerPanel)) {
                queryContainerPanel.add(queryPanel, BorderLayout.CENTER);
                searchContainerPanel.removeAll();
                similarityContainerPanel.removeAll();
                tmqlContainerPanel.removeAll();
            }
            else if(p.equals(tmqlContainerPanel)) {
                tmqlContainerPanel.add(tmqlPanel, BorderLayout.CENTER);
                searchContainerPanel.removeAll();
                queryContainerPanel.removeAll();
                similarityContainerPanel.removeAll();
            }
            currentContainerPanel = p;
            this.revalidate();
        }
    }
}