Java Code Examples for javax.swing.JComponent#isVisible()

The following examples show how to use javax.swing.JComponent#isVisible() . 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: ThreadsCPUView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension preferredLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getPreferredSize();
        Dimension dim2 = search.getPreferredSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getPreferredSize();
    } else if (search != null) {
        dim = search.getPreferredSize();
    }
    
    if ((filter != null || search != null) /*&& hasBottomFilterFindMargin()*/)
        dim.height += 1;
    
    return dim;
}
 
Example 2
Source File: DataView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Dimension minimumLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getMinimumSize();
        Dimension dim2 = search.getMinimumSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getMinimumSize();
    } else if (search != null) {
        dim = search.getMinimumSize();
    }
    
    if ((filter != null || search != null) && hasBottomFilterFindMargin())
        dim.height += 1;
    
    return dim;
}
 
Example 3
Source File: PopupManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Removes popup component from textComponent root pane
 *  @param popup popup component to be removed from
 *  root pane of the text component.
 */
public void uninstall(JComponent popup) {
    JComponent oldPopup = this.popup;

    if (oldPopup != null) {
        if (oldPopup.isVisible()) {
            oldPopup.setVisible(false);
        }
        removeFromRootPane(oldPopup);
        this.popup = null;
    }

    if (popup != null && popup != oldPopup) {
        if (popup.isVisible()) {
            popup.setVisible(false);
        }
        removeFromRootPane(popup);
    }
}
 
Example 4
Source File: MemoryView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension minimumLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getMinimumSize();
        Dimension dim2 = search.getMinimumSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getMinimumSize();
    } else if (search != null) {
        dim = search.getMinimumSize();
    }
    
    if ((filter != null || search != null) /*&& hasBottomFilterFindMargin()*/)
        dim.height += 1;
    
    return dim;
}
 
Example 5
Source File: MockComponent.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Temporarily massage this component so it is visible, enabled, unselected,
 * unfocused, etc.
 */
private void storeState(JComponent c) {
	if (c instanceof AbstractButton) {
		AbstractButton b = (AbstractButton) c;
		b.putClientProperty(WAS_SELECTED, new Boolean(b.isSelected()));
		b.putClientProperty(WAS_FOCUS_PAINTED, new Boolean(b.isSelected()));
		b.setSelected(false);
		b.setFocusPainted(false);
	}
	if (c.isEnabled() == false) {
		c.putClientProperty(WAS_ENABLED, new Boolean(c.isEnabled()));
		c.setEnabled(true);
	}
	if (c.isVisible() == false) {
		c.putClientProperty(WAS_VISIBLE, new Boolean(c.isVisible()));
		c.setVisible(true);
	}
	for (int a = 0; a < c.getComponentCount(); a++) {
		if (c.getComponent(a) instanceof JComponent) {
			storeState((JComponent) c.getComponent(a));
		}
	}
}
 
Example 6
Source File: LSettingsGui.java    From scelight with Apache License 2.0 6 votes vote down vote up
/**
 * Binds the visibility of the specified component to the user's computer skill level. The skill level is the {@link LSettings#SKILL_LEVEL} taken from
 * {@link LEnv#LAUNCHER_SETTINGS}. <strong>Also executes the listener!</strong>
 * 
 * @param comp component whose visibility to be controlled
 * @param minSkillLevel minimal skill level required for the component to be visible
 * 
 * @param hiddenSelected if not <code>null</code>, and if the component (which must be an {@link AbstractButton} in this case) has a different selection
 *            state than this value case upon being hidden), the component selection will be inverted with a {@link AbstractButton#doClick()} call (which
 *            also fires an event)
 * 
 * @throws IllegalArgumentException if <code>hiddenSelected</code> is not <code>null</code> and comp is not an {@link AbstractButton}
 * 
 * @see #bindVisibilityToSkillLevel(JComponent, ISkillLevel)
 */
public static void bindVisibilityToSkillLevel( final JComponent comp, final ISkillLevel minSkillLevel, final Boolean hiddenSelected ) {
	if ( hiddenSelected != null && !( comp instanceof AbstractButton ) )
		throw new IllegalArgumentException( "hiddenSelected can only be specified if component is an AbstractButton!" );
	
	final ISettingChangeListener scl = new ISettingChangeListener() {
		@Override
		public void valuesChanged( final ISettingChangeEvent event ) {
			if ( event.affected( LSettings.SKILL_LEVEL ) ) {
				comp.setVisible( minSkillLevel.isAtLeast() );
				if ( hiddenSelected != null && !comp.isVisible() && hiddenSelected != ( (AbstractButton) comp ).isSelected() )
					( (AbstractButton) comp ).doClick( 0 );
			}
		}
	};
	addBindExecuteScl( scl, LEnv.LAUNCHER_SETTINGS, LSettings.SKILL_LEVEL.SELF_SET, comp );
}
 
Example 7
Source File: RowLayout.java    From pumpernickel with MIT License 6 votes vote down vote up
private int getMaximumExtraHeight(Row row, int[] columnWidths) {
	int maxExtraHeight = 0;
	for (int a = 0; a < row.columns.length; a++) {
		if (row.columns[a] != null) {
			int columnWidth = columnWidths[a];
			for (int b = 0; b < row.columns[a].components.length; b++) {
				JComponent jc = row.columns[a].components[b];
				ComponentConstraints c = row.columns[a].constraints[b];
				if (jc != null
						&& jc.isVisible()
						&& c.verticalPriority == profile.maxVisiblePriority) {
					Dimension maxSize = getMaximumSize(jc, columnWidth);

					if (maxSize == null)
						maxSize = jc.getMaximumSize();
					Dimension preferredSize = getPreferredSize(jc);

					maxExtraHeight = Math.max(maxExtraHeight,
							maxSize.height - preferredSize.height);
				}
			}
		}
	}
	return maxExtraHeight;
}
 
Example 8
Source File: MemoryView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension preferredLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getPreferredSize();
        Dimension dim2 = search.getPreferredSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getPreferredSize();
    } else if (search != null) {
        dim = search.getPreferredSize();
    }
    
    if ((filter != null || search != null) /*&& hasBottomFilterFindMargin()*/)
        dim.height += 1;
    
    return dim;
}
 
Example 9
Source File: ThreadsMemoryView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension minimumLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getMinimumSize();
        Dimension dim2 = search.getMinimumSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getMinimumSize();
    } else if (search != null) {
        dim = search.getMinimumSize();
    }
    
    if ((filter != null || search != null) /*&& hasBottomFilterFindMargin()*/)
        dim.height += 1;
    
    return dim;
}
 
Example 10
Source File: MemorySamplerViewSupport.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension minimumLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;

    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;

    Dimension dim = new Dimension();

    if (filter != null && search != null) {
        Dimension dim1 = filter.getMinimumSize();
        Dimension dim2 = search.getMinimumSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getMinimumSize();
    } else if (search != null) {
        dim = search.getMinimumSize();
    }

    if ((filter != null || search != null) /*&& hasBottomFilterFindMargin()*/)
        dim.height += 1;

    return dim;
}
 
Example 11
Source File: ThreadsMemoryView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension preferredLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getPreferredSize();
        Dimension dim2 = search.getPreferredSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getPreferredSize();
    } else if (search != null) {
        dim = search.getPreferredSize();
    }
    
    if ((filter != null || search != null) /*&& hasBottomFilterFindMargin()*/)
        dim.height += 1;
    
    return dim;
}
 
Example 12
Source File: DataView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension preferredLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getPreferredSize();
        Dimension dim2 = search.getPreferredSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getPreferredSize();
    } else if (search != null) {
        dim = search.getPreferredSize();
    }
    
    if ((filter != null || search != null) && hasBottomFilterFindMargin())
        dim.height += 1;
    
    return dim;
}
 
Example 13
Source File: MemoryView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Dimension preferredLayoutSize(Container parent) {
    JComponent filter = filterPanel;
    if (filter != null && !filter.isVisible()) filter = null;
    
    JComponent search = searchPanel;
    if (search != null && !search.isVisible()) search = null;
    
    Dimension dim = new Dimension();
    
    if (filter != null && search != null) {
        Dimension dim1 = filter.getPreferredSize();
        Dimension dim2 = search.getPreferredSize();
        dim.width = dim1.width + dim2.width + 1;
        dim.height = Math.max(dim1.height, dim2.height);
    } else if (filter != null) {
        dim = filter.getPreferredSize();
    } else if (search != null) {
        dim = search.getPreferredSize();
    }
    
    if ((filter != null || search != null) /*&& hasBottomFilterFindMargin()*/)
        dim.height += 1;
    
    return dim;
}
 
Example 14
Source File: RowLayout.java    From pumpernickel with MIT License 5 votes vote down vote up
public boolean isRowVisible(int rowIndex) {
	Row row = rows.get(rowIndex);
	int componentsVisible = 0;
	for (JComponent jc : row.componentIterator()) {
		if (jc.isVisible()) {
			componentsVisible++;
		} else {
			return false;
		}
	}
	return componentsVisible > 0;
}
 
Example 15
Source File: ApplyOptionChangesListener.java    From collect-earth with MIT License 5 votes vote down vote up
public void savePropertyValues() {
	final Set<Enum<?>> keySet = propertyToComponent.keySet();
	for (final Enum<?> propertyKey : keySet) {
		final JComponent component = propertyToComponent.get(propertyKey)[0];
		if( !component.isVisible() ) {
			setPropertyValue(propertyKey, "");
		}else {
			if (component instanceof JTextComponent) {
				setPropertyValue(propertyKey, ((JTextComponent) component).getText());
			} else if (component instanceof JCheckBox) {
				setPropertyValue(propertyKey, ((JCheckBox) component).isSelected() + ""); //$NON-NLS-1$
			} else if (component instanceof JComboBox) {
				if (((JComboBox) component).getItemAt(0) instanceof ComboBoxItem) {
					setPropertyValue(propertyKey,
							((ComboBoxItem) ((JComboBox) component).getSelectedItem()).getNumberOfPoints() + ""); //$NON-NLS-1$
				} else if (((JComboBox) component).getItemAt(0) instanceof String) {
					setPropertyValue(propertyKey, ((String) ((JComboBox) component).getSelectedItem() ) ); //$NON-NLS-1$
				} else if (((JComboBox) component).getItemAt(0) instanceof SAMPLE_SHAPE) {
					setPropertyValue(propertyKey,  ( (SAMPLE_SHAPE) ((JComboBox) component).getSelectedItem() ).name() );
				}
			} else if (component instanceof JList) {
				setPropertyValue(propertyKey, ((JList) component).getSelectedValue() + ""); //$NON-NLS-1$
			} else if (component instanceof JRadioButton) {
				final JComponent[] jComponents = propertyToComponent.get(propertyKey);
				for (final JComponent jComponent : jComponents) {
					if (((JRadioButton) jComponent).isSelected()) {
						setPropertyValue(propertyKey, ((JRadioButton) jComponent).getName());
					}
				}
			} else if (component instanceof JFilePicker) {
				setPropertyValue(propertyKey, ((JFilePicker) component).getSelectedFilePath());
			}
		}
	}
}
 
Example 16
Source File: VectorRenderer.java    From energy2d with GNU Lesser General Public License v3.0 5 votes vote down vote up
void renderHeatFlux(float[][] t, float[][] k, JComponent c, Graphics2D g, float scale, float minSquare, boolean dotForZero) {

		if (!c.isVisible())
			return;

		int w = c.getWidth();
		int h = c.getHeight();
		float dx = (float) w / (float) nx;
		float dy = (float) h / (float) ny;

		g.setStroke(stroke);
		int x, y;
		float uij, vij;
		for (int i = 1; i < nx - 1; i += spacing) {
			x = Math.round(i * dx);
			for (int j = 1; j < ny - 1; j += spacing) {
				y = Math.round(j * dy);
				uij = -k[i][j] * (t[i + 1][j] - t[i - 1][j]) / (2 * dx);
				vij = -k[i][j] * (t[i][j + 1] - t[i][j - 1]) / (2 * dy);
				g.setColor(view.getContrastColor(x, y));
				if (uij * uij + vij * vij > minSquare) {
					drawVector(g, x, y, uij, vij, scale);
				} else {
					if (dotForZero)
						g.fillOval(x, y, 4, 4);
				}
			}
		}

	}
 
Example 17
Source File: JavaReferencesPlugin.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void showObjectsView() {
    JComponent c = objectsView.getComponent();
    if (c.isVisible()) return;
    
    c.setVisible(true);
    
    component.removeAll();
    component.add(c, BorderLayout.CENTER);
    
    mergedRequest = false;
    
    component.invalidate();
    component.revalidate();
    component.repaint();
}
 
Example 18
Source File: ContainerPanel.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Dimension getPreferredSize() {
	Dimension size = panel.getPreferredSize();
	JComponent scrollBar = getVerticalScrollBar();
	if (scrollBar.isVisible()) {
		/*
		 * Try to claim a bit more space if the user enlarges the window and
		 * there's not enough space sidewise.
		 */
		size.width += scrollBar.getWidth();
	}
	return size;
}
 
Example 19
Source File: ThreadCheckingRepaintManager.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
private void checkThread(JComponent comp) throws Exception
{
	if (comp.isVisible())
	{
		final Component root = comp.getRootPane();
		if (root != null && root.isVisible())
		{
			if (!SwingUtilities.isEventDispatchThread())
			{
                   // i18n[ThreadCheckingRepaintManager.workinwrongthread=GUI work done in wrong thread]
				//throw new Exception(s_stringMgr.getString("ThreadCheckingRepaintManager.workinwrongthread"));
			}
		}
	}
}
 
Example 20
Source File: IntroduceMethodPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isAvailable(JComponent c) {
    return c.isVisible() && c.isEnabled();
}