Java Code Examples for java.awt.Component

The following are top voted examples for showing how to use java.awt.Component. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: DragGestureRecognizer.java   Source Code and License 6 votes vote down vote up
/**
 * Deserializes this {@code DragGestureRecognizer}. This method first
 * performs default deserialization for all non-{@code transient}
 * fields. This object's {@code DragGestureListener} is then
 * deserialized as well by using the next object in the stream.
 *
 * @since 1.4
 */
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream s)
    throws ClassNotFoundException, IOException
{
    ObjectInputStream.GetField f = s.readFields();

    DragSource newDragSource = (DragSource)f.get("dragSource", null);
    if (newDragSource == null) {
        throw new InvalidObjectException("null DragSource");
    }
    dragSource = newDragSource;

    component = (Component)f.get("component", null);
    sourceActions = f.get("sourceActions", 0) & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
    events = (ArrayList<InputEvent>)f.get("events", new ArrayList<>(1));

    dragGestureListener = (DragGestureListener)s.readObject();
}
 
Example 2
Project: openjdk-jdk10   File: Util.java   Source Code and License 6 votes vote down vote up
/**
 * Moves mouse pointer in the center of a given {@code comp} component
 * and performs a left mouse button click using the {@code robot} parameter
 * with the {@code delay} delay between press and release.
 */
public static void clickOnComp(final Component comp, final Robot robot, int delay) {
    pointOnComp(comp, robot);
    robot.delay(delay);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.delay(delay);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
Example 3
Project: incubator-netbeans   File: OutlineViewDropSupport.java   Source Code and License 6 votes vote down vote up
private void checkStoredGlassPane() {
    // remember current glass pane to set back at end of dragging over this compoment
    if (!DropGlassPane.isOriginalPaneStored() || dropPane == null) {
        if (DropGlassPane.isOriginalPaneStored()) {
            // Original panel is stored, but dropPane == null, see #236349.
            DropGlassPane.putBackOriginal();
        }
        Component comp = table.getRootPane().getGlassPane();
        DropGlassPane.setOriginalPane(table, comp, comp.isVisible());

        // set glass pane for paint selection line
        dropPane = DropGlassPane.getDefault(table);
        table.getRootPane().setGlassPane(dropPane);
        dropPane.revalidate();
        dropPane.setVisible(true);
        log("dropPane was set"); // NOI18N
    }
}
 
Example 4
Project: ramus   File: DFDSRoleOptionsDialog.java   Source Code and License 6 votes vote down vote up
@Override
protected Component createFirstTab(JTabbedPane pane) {
    sectorRowsEditor = new SectorRowsEditor(dataPlugin, framework,
            framework.getAccessRules());
    sectorNameEditor = new SectorNameEditor(dataPlugin, framework,
            framework.getAccessRules()) {
        @Override
        protected void createReplacementPanel(JPanel ignoreMe) {
        }

        @Override
        public Stream getStream() {
            return sectorRowsEditor.getStream();
        }
    };
    sectorNameEditor.box.setVisible(false);
    sectorRowsEditor.setSectorNameEditor(sectorNameEditor);
    pane.addTab(ResourceLoader.getString("name"), sectorRowsEditor);
    return sectorNameEditor;
}
 
Example 5
Project: powertext   File: WrappedSyntaxView.java   Source Code and License 6 votes vote down vote up
private void handleDocumentEvent(DocumentEvent e, Shape a,
									ViewFactory f) {
	int n = calculateLineCount();
	if (this.nlines != n) {
		this.nlines = n;
		WrappedSyntaxView.this.preferenceChanged(this, false, true);
		// have to repaint any views after the receiver.
		RSyntaxTextArea textArea = (RSyntaxTextArea)getContainer();
		textArea.repaint();
		// Must also revalidate container so gutter components, such
		// as line numbers, get updated for this line's new height
		Gutter gutter = RSyntaxUtilities.getGutter(textArea);
		if (gutter!=null) {
			gutter.revalidate();
			gutter.repaint();
		}
	}
	else if (a != null) {
		Component c = getContainer();
		Rectangle alloc = (Rectangle) a;
		c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
	}
}
 
Example 6
Project: openjdk-jdk10   File: JMenuOperator.java   Source Code and License 6 votes vote down vote up
static DescriptablePathChooser converChoosers(final ComponentChooser[] choosers) {
    return (new DescriptablePathChooser() {
        @Override
        public boolean checkPathComponent(int depth, Object component) {
            return choosers[depth].checkComponent((Component) component);
        }

        @Override
        public int getDepth() {
            return choosers.length;
        }

        @Override
        public String getDescription() {
            return createDescription(choosers);
        }

        @Override
        public String toString() {
            return "JMenuOperator.converChoosers.DescriptablePathChooser{description = " + getDescription() + '}';
        }
    });
}
 
Example 7
Project: incubator-netbeans   File: GlobalActionContextImpl.java   Source Code and License 6 votes vote down vote up
/** Requests refresh of our lookup everytime component is chagned.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    if (TopComponent.Registry.PROP_ACTIVATED.equals (evt.getPropertyName())) {
        org.openide.util.Utilities.actionsGlobalContext ().lookup (javax.swing.ActionMap.class);
    }
    if ("permanentFocusOwner".equals(evt.getPropertyName())) {
        Component[] arr = { (Component)evt.getNewValue() };
        if (arr[0] instanceof AbstractButton) {
            Action a = ((AbstractButton)arr[0]).getAction();
            if (a instanceof ContextAwareAction) {
                // ignore focus change into a button with our action
                return;
            }
        }
        blickActionMap(null, arr);
    }
}
 
Example 8
Project: QN-ACTR-Release   File: ConnectionsPanel.java   Source Code and License 6 votes vote down vote up
protected void createRenderers() {
	final TableCellRenderer boolRend = getDefaultRenderer(Boolean.class);
	setDefaultRenderer(Boolean.class, new DisabledCellRenderer() {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		@Override
		public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
			Component cbox = boolRend.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
			cbox.setEnabled(true);
			if (value == null) {
				Component disabled = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
				cbox.setBackground(disabled.getBackground());
				cbox.setEnabled(false);
			}
			return cbox;
		}
	});
}
 
Example 9
Project: Hotel-Properties-Management-System   File: LanguageCmbBox.java   Source Code and License 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
	

	int selectedIndex = ((Integer) value).intValue();

	if (isSelected) {
		setBackground(list.getSelectionBackground());
		setForeground(list.getSelectionForeground());
	} else {
		setBackground(list.getBackground());
		setForeground(list.getForeground());
	}

	ImageIcon icon = iconArray[selectedIndex];
	setIcon(icon);
	
	return this;
}
 
Example 10
Project: incubator-netbeans   File: ThinBevelBorder.java   Source Code and License 6 votes vote down vote up
protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();
    int h = height;
    int w = width;

    g.translate(x, y);

    g.setColor(getHighlightOuterColor(c));
    g.drawLine(0, 0, 0, h - 2);
    g.drawLine(1, 0, w - 2, 0);

    g.setColor(getShadowOuterColor(c));
    g.drawLine(0, h - 1, w - 1, h - 1);
    g.drawLine(w - 1, 0, w - 1, h - 2);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 11
Project: rapidminer   File: ParameterTupelCellEditor.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
	String[] tupel;
	if (value instanceof String) {
		tupel = ParameterTypeTupel.transformString2Tupel((String) value);
	} else {
		tupel = (String[]) value;
	}
	if (panel == null) {
		constructPanel(tupel);
	}
	for (int i = 0; i < editors.length; i++) {
		editors[i].getTableCellEditorComponent(null, tupel[i], false, 0, 0);
	}
	return panel;
}
 
Example 12
Project: org.alloytools.alloy   File: OurBorder.java   Source Code and License 6 votes vote down vote up
/** This method is called by Swing to actually draw the borders. */
public void paintBorder(Component component, Graphics graphics, int x, int y, int width, int height) {
	if (width < 1 || height < 1)
		return;
	Color old = graphics.getColor();
	if (top != null) {
		graphics.setColor(top);
		graphics.drawLine(x, y, x + width - 1, y);
	}
	if (bottom != null) {
		graphics.setColor(bottom);
		graphics.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
	}
	if (left != null) {
		graphics.setColor(left);
		graphics.drawLine(x, y, x, y + height - 1);
	}
	if (right != null) {
		graphics.setColor(right);
		graphics.drawLine(x + width - 1, y, x + width - 1, y + height - 1);
	}
	graphics.setColor(old);
}
 
Example 13
Project: incubator-netbeans   File: TemplateChooserPanel.java   Source Code and License 6 votes vote down vote up
@Override
public Component getComponent() {
    if (gui == null) {
        gui = new TemplateChooserPanelGUI(includeTemplatesWithProjects);
        gui.addChangeListener(this);
        gui.setDefaultActionListener(new ActionListener() {

            @Override
            public void actionPerformed( ActionEvent e ) {
                if( null != wizard ) {
                    wizard.doNextClick();
                }
            }
        });
    }
    return gui;
}
 
Example 14
Project: incubator-netbeans   File: FilesModifiedConfirmation.java   Source Code and License 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus) {
    super.getListCellRendererComponent(list,
                                       value,
                                       index,
                                       isSelected,
                                       cellHasFocus);
    if (isSelected){
        setBackground(UIManager.getColor("List.selectionBackground")); //NOI18N
        setForeground(UIManager.getColor("List.selectionForeground")); //NOI18N
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    return this;
}
 
Example 15
Project: EasyDragDrop   File: MainFrame.java   Source Code and License 6 votes vote down vote up
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Dimension arcs = new Dimension(40, 40);
    Graphics2D graphics = (Graphics2D) g;
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    graphics.setColor(new Color(106, 117, 144));
    graphics.fillRoundRect(0, 0, width - 1, height - 1, arcs.width, arcs.height);//paint background

    graphics.setClip(null);
    graphics.drawRoundRect(0, 0, width - 1, height - 1, arcs.width, arcs.height);//paint border
}
 
Example 16
Project: OpenJSharp   File: SynthTreeUI.java   Source Code and License 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    if (!useTreeColors && (sel || hasFocus)) {
        SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
                     getUIOfType(getUI(), SynthLabelUI.class),
                           sel, hasFocus, tree.isEnabled(), false);
    }
    else {
        SynthLookAndFeel.resetSelectedUI();
    }
    return super.getTreeCellRendererComponent(tree, value, sel,
                                              expanded, leaf, row, hasFocus);
}
 
Example 17
Project: Tarski   File: JTableRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * 
 */
public static JTableRenderer getVertex(Component component)
{
	while (component != null)
	{
		if (component instanceof JTableRenderer)
		{
			return (JTableRenderer) component;
		}
		component = component.getParent();
	}

	return null;
}
 
Example 18
Project: rapidminer   File: PerformanceVectorViewer.java   Source Code and License 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
	JLabel listCellRendererComponent = (JLabel) super.getListCellRendererComponent(list,
			value.toString().replace('_', ' '), index, isSelected, cellHasFocus);
	if (!isSelected) {
		listCellRendererComponent.setBackground(Colors.PANEL_BACKGROUND);
	}
	return spacerPanel;
}
 
Example 19
Project: VASSAL-src   File: WarningDialog.java   Source Code and License 5 votes vote down vote up
public static Future<?> showDetailsDisableable(
  Component parent,
  Throwable thrown,
  String details,
  Object key,
  String messageKey,
  Object... args)
{
  return ProblemDialog.showDetailsDisableable(
    JOptionPane.WARNING_MESSAGE, parent,
    thrown, details, key, messageKey, args
  );
}
 
Example 20
Project: OpenJSharp   File: GroupLayout.java   Source Code and License 5 votes vote down vote up
/**
 * Creates a {@code GroupLayout} for the specified {@code Container}.
 *
 * @param host the {@code Container} the {@code GroupLayout} is
 *        the {@code LayoutManager} for
 * @throws IllegalArgumentException if host is {@code null}
 */
public GroupLayout(Container host) {
    if (host == null) {
        throw new IllegalArgumentException("Container must be non-null");
    }
    honorsVisibility = true;
    this.host = host;
    setHorizontalGroup(createParallelGroup(Alignment.LEADING, true));
    setVerticalGroup(createParallelGroup(Alignment.LEADING, true));
    componentInfos = new HashMap<Component,ComponentInfo>();
    tmpParallelSet = new HashSet<Spring>();
}
 
Example 21
Project: jdk8u-jdk   File: SwingPaintEventDispatcher.java   Source Code and License 5 votes vote down vote up
public boolean queueSurfaceDataReplacing(Component c, Runnable r) {
    if (c instanceof RootPaneContainer) {
        AppContext appContext = SunToolkit.targetToAppContext(c);
        RepaintManager.currentManager(appContext).
                nativeQueueSurfaceDataRunnable(appContext, c, r);
        return true;
    }
    return super.queueSurfaceDataReplacing(c, r);
}
 
Example 22
Project: openjdk-jdk10   File: XMBeanNotifications.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized Component prepareRenderer(
        TableCellRenderer renderer, int row, int column) {
    //In case we have a repaint thread that is in the process of
    //repainting an obsolete table, just ignore the call.
    //It can happen when MBean selection is switched at a very quick rate
    if (row >= getRowCount()) {
        return null;
    }

    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }
    UserDataCell cell = getUserDataCell(row, 2);
    if (column == 2 && cell != null) {
        comp.setFont(boldFont);
        int size = cell.getHeight();
        if (size > 0) {
            if (getRowHeight(row) != size) {
                setRowHeight(row, size);
            }
        }
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example 23
Project: incubator-netbeans   File: ResultsOutlineCellRenderer.java   Source Code and License 5 votes vote down vote up
private void setToolTip(Component renderer, Property<?> property)
        throws IllegalAccessException, InvocationTargetException {
    if (renderer instanceof JLabel) {
        Object val = property.getValue();
        if (val != null) {
            ((JLabel) renderer).setToolTipText(val.toString());
        }
    }
}
 
Example 24
Project: incubator-netbeans   File: ButtonPopupSwitcher.java   Source Code and License 5 votes vote down vote up
private void changeSelection( MouseEvent e ) {
    Point p = e.getPoint();
    // It may have occured on the button that invoked the tabtable
    if (e.getSource() != this) {
        p = SwingUtilities.convertPoint((Component) e.getSource(), p, pTable);
    }
    if (pTable.contains(p)) {
        int row = pTable.rowAtPoint(p);
        int col = pTable.columnAtPoint(p);
        pTable.changeSelection(row, col, false, false);
    } else {
        pTable.clearSelection();
    }
}
 
Example 25
Project: jdk8u-jdk   File: InputContext.java   Source Code and License 5 votes vote down vote up
static Window getComponentWindow(Component component) {
    while (true) {
        if (component == null) {
            return null;
        } else if (component instanceof Window) {
            return (Window) component;
        } else {
            component = component.getParent();
        }
    }
}
 
Example 26
Project: incubator-netbeans   File: ButtonPopupSwitcher.java   Source Code and License 5 votes vote down vote up
private void changeSelection( MouseEvent e ) {
    Point p = e.getPoint();
    // It may have occured on the button that invoked the tabtable
    if (e.getSource() != this) {
        p = SwingUtilities.convertPoint((Component) e.getSource(), p, pTable);
    }
    if (pTable.contains(p)) {
        int row = pTable.rowAtPoint(p);
        int col = pTable.columnAtPoint(p);
        pTable.changeSelection(row, col, false, false);
    } else {
        pTable.clearSelection();
    }
}
 
Example 27
Project: openjdk-jdk10   File: JLabelOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code JLabel.getLabelFor()} through queue
 */
public Component getLabelFor() {
    return (runMapping(new MapAction<Component>("getLabelFor") {
        @Override
        public Component map() {
            return ((JLabel) getSource()).getLabelFor();
        }
    }));
}
 
Example 28
Project: javaportfolio   File: TransferDialog.java   Source Code and License 5 votes vote down vote up
/**
 * Set up and show the dialog. The first Component argument determines which
 * frame the dialog depends on; it should be a component in the dialog's
 * controlling frame. The second Component argument should be null if you
 * want the dialog to come up with its left corner in the center of the
 * screen; otherwise, it should be the component on top of which the dialog
 * should appear.
 */

public TransferDialog(Component frameComp, Component locationComp,
		String title,  I_TickerManager tickerManager) {
	super(frameComp, locationComp, title, tickerManager);

	String[] currencies = {"EUR", "USD", "SEK" , "NOK"};
	currencyList = new JComboBox(currencies);
	currencyList.setEditable(true);
	currencyList.addActionListener(this);
	currencyList.setSelectedIndex(0);
	currencyList.setActionCommand(CURRENCY_CHANGED);
	
	totalCostField = new JTextField(FIELD_LEN);
	totalCostField.setEditable(true);
	totalCostField.setText("");		
	totalCostField.addKeyListener(this);
	
	dateFieldLabel = new JLabel("Maksupäivä: ");
	dateFieldLabel.setLabelFor(dateChooser);


	totalCostFieldLabel = new JLabel("yhteensä: ");
	totalCostFieldLabel.setLabelFor(totalCostField);

	currencyFieldLabel = new JLabel("Valuutta: ");
	
	updateRateFieldCcy((String) currencyList.getSelectedItem(), true);
	init(getDialogLabels(), getDialogComponents());
}
 
Example 29
Project: openjdk-jdk10   File: KeyEventDriver.java   Source Code and License 5 votes vote down vote up
@Override
public void pushKey(ComponentOperator oper, int keyCode, int modifiers, Timeout pushTime) {
    Component nativeContainer = findNativeParent(oper.getSource());
    pressKey(nativeContainer, keyCode, modifiers);
    pushTime.sleep();
    releaseKey(nativeContainer, keyCode, modifiers);
}
 
Example 30
Project: Pogamut3   File: Explorer.java   Source Code and License 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    String label;
    // First element in the list is new action/sense whatever...
    if (index == 0) {
        label = value.toString();
    } else {
        T item = (T) value;
        label = getRenderedLabel(item);
    }
    return listRenderer.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
}
 
Example 31
Project: FreeCol   File: PlayersTable.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Component getTableCellRendererComponent(JTable table,
    Object value, boolean isSelected, boolean hasFocus,
    int row, int column) {
    final Player player = (Player)table.getValueAt(row,
        PlayersTable.PLAYER_COLUMN);
    final NationType nationType = ((Nation)table.getValueAt(row,
            PlayersTable.NATION_COLUMN)).getType();
    JLabel label;
    switch (advantages) {
    case SELECTABLE:
        return Utility.localizedLabel(Messages.nameKey((player == null)
                ? nationType
                : player.getNationType()));
    case FIXED:
        label = Utility.localizedLabel(Messages.nameKey(nationType));
        break;
    case NONE:
    default:
        label = Utility.localizedLabel("none");
        break;
    }
    label.setForeground((player != null && player.isReady())
        ? Color.GRAY
        : table.getForeground());
    label.setBackground(table.getBackground());
    Utility.localizeToolTip(this, StringTemplate
        .key(advantages.getShortDescriptionKey()));
    return label;
}
 
Example 32
Project: ramus   File: MainPanel.java   Source Code and License 5 votes vote down vote up
private Component createBottom() {
    final JPanel panel = new JPanel(new GridLayout(1, 4, 5, 0));
    panel.add(bBack);
    panel.add(bNext);
    panel.add(bCancel);
    panel.add(bFinish);

    final JPanel p = new JPanel(new FlowLayout());

    p.add(panel);

    final JPanel res = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    final JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    p1.add(etap);

    c.weightx = 1.0;
    c.gridx = 0;
    c.gridy = 0;

    res.add(p1, c);

    c.weightx = 0;
    c.gridx = 1;
    c.gridy = 0;

    res.add(p, c);

    return res;
}
 
Example 33
Project: incubator-netbeans   File: DTDWizardIterator.java   Source Code and License 5 votes vote down vote up
/**
 * Initialization of the wizard iterator.
 */
public void initialize(TemplateWizard wizard) {
    index = 0;
    Project project = Templates.getProject( wizard );
    panels = createPanels (project, wizard);
    
    // Creating steps.
    Object prop = wizard.getProperty (WizardDescriptor.PROP_CONTENT_DATA); // NOI18N
    String[] beforeSteps = null;
    if (prop instanceof String[]) {
        beforeSteps = (String[])prop;
    }
    String[] steps = createSteps (beforeSteps, panels);
    
    for (int i = 0; i < panels.length; i++) {
        Component c = panels[i].getComponent ();
        if (steps[i] == null) {
            // Default step name to component name of panel.
            // Mainly useful for getting the name of the target
            // chooser to appear in the list of steps.
            steps[i] = c.getName ();
        }
        if (c instanceof JComponent) { // assume Swing components
            JComponent jc = (JComponent) c;
            // Step #.
            jc.putClientProperty (WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, Integer.valueOf(i)); // NOI18N
            // Step name (actually the whole list for reference).
            jc.putClientProperty (WizardDescriptor.PROP_CONTENT_DATA, steps); // NOI18N
        }
    }        
}
 
Example 34
Project: geomapapp   File: WWCustomDB.java   Source Code and License 5 votes vote down vote up
private Component createPlotAllCheckbox() {
	drawAllIcons = new JCheckBox("Draw All Center Icons",false);
	drawAllIcons.addActionListener(this);
	drawAllIcons.setActionCommand("drawAll");
	drawAllIcons.setEnabled(false);
	return drawAllIcons;
}
 
Example 35
Project: VASSAL-src   File: ExtensionTree.java   Source Code and License 5 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
    boolean expanded, boolean leaf, int row, boolean hasFocus) {

  Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
      hasFocus);
  c.setForeground(isEditable((DefaultMutableTreeNode) value) ? Color.BLACK : Color.GRAY);

  return c;
}
 
Example 36
Project: incubator-netbeans   File: AwtDetailsProvider.java   Source Code and License 5 votes vote down vote up
protected Component getComponent(FontBuilder builder) {
    JLabel label = new JLabel();
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setFont(builder.createInstance());
    label.setText(Bundle.FontView_Preview());
    return label;
}
 
Example 37
Project: Equella   File: Wizard.java   Source Code and License 5 votes vote down vote up
/**
 * Create the installation window which the pages appear in.
 */
private void createWindow()
{
	JImage sideImage = new JImage(getClass().getResource(imagePath));
	sideImage.setVerticalAlignment(SwingConstants.TOP);
	sideImage.setAlignmentY(Component.TOP_ALIGNMENT);

	pageArea = new JPanel();
	pageArea.setLayout(new GridLayout(1, 1));

	JSeparator bar = new JSeparator();

	navArea = new JPanel();
	navArea.setLayout(new GridLayout(1, 1));

	JPanel bottom = new JPanel(new BorderLayout(5, 5));
	bottom.add(bar, BorderLayout.NORTH);
	bottom.add(navArea, BorderLayout.CENTER);

	JPanel all = new JPanel(new BorderLayout(5, 5));
	all.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
	all.add(sideImage, BorderLayout.WEST);
	all.add(pageArea, BorderLayout.CENTER);
	all.add(bottom, BorderLayout.SOUTH);

	frame = new JFrame();
	frame.getContentPane().add(all);
	frame.setTitle(productName);
	frame.setResizable(false);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 38
Project: ramus   File: Tab.java   Source Code and License 5 votes vote down vote up
@Override
public void mouseEntered(MouseEvent e) {
    Component component = e.getComponent();
    if (component instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) component;
        button.setBorderPainted(true);
    }
}
 
Example 39
Project: jdk8u-jdk   File: XMBeanAttributes.java   Source Code and License 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table,
                                               Object value,
                                               boolean isSelected,
                                               boolean hasFocus,
                                               int row,
                                               int column) {
    return comp;
}
 
Example 40
Project: VASSAL-src   File: ComponentSplitter.java   Source Code and License 5 votes vote down vote up
/**
 * Return the first SplitPane ancestor with a different orientation from this SplitPane
 *
 * @return
 */
public SplitPane getTransverseSplit() {
  SplitPane split = null;
  for (Component c = getParent(); c != null; c = c.getParent()) {
    if (c instanceof SplitPane) {
      SplitPane p = (SplitPane) c;
      if (p.getOrientation() != getOrientation() && SwingUtilities.isDescendingFrom(this, p.getBaseComponent())) {
        split = p;
        break;
      }
    }
  }
  return split;
}
 
Example 41
Project: incubator-netbeans   File: ProfilerPopup.java   Source Code and License 5 votes vote down vote up
PopupPane(Component content, boolean resize) {
    super(new BorderLayout());
    add(content, BorderLayout.CENTER);
    
    setFocusCycleRoot(true);
    setFocusTraversalPolicyProvider(true);
    setFocusTraversalPolicy(new PopupFocusTraversalPolicy());
    
    if (UIUtils.isAquaLookAndFeel()) {
        if (resize) {
            setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
            addMouseListener(this);
            addMouseMotionListener(this);
        }
    } else {
        Border border = BorderFactory.createLineBorder(UIUtils.getDisabledLineColor());
        
        if (resize) {
            setBorder(BorderFactory.createCompoundBorder(border,
                      BorderFactory.createEmptyBorder(8, 8, 8, 8)));
            addMouseListener(this);
            addMouseMotionListener(this);
        } else {
            setBorder(border);
        }
    }
}
 
Example 42
Project: openjdk-jdk10   File: TextComponentOperator.java   Source Code and License 5 votes vote down vote up
@Override
public boolean checkComponent(Component comp) {
    if (comp instanceof TextComponent) {
        if (((TextComponent) comp).getText() != null) {
            return (comparator.equals(((TextComponent) comp).getText(),
                    label));
        }
    }
    return false;
}
 
Example 43
Project: OpenJSharp   File: BasicRootPaneUI.java   Source Code and License 5 votes vote down vote up
public boolean isEnabled(Object sender) {
    String key = getName();
    if(key == POST_POPUP) {
        MenuElement[] elems = MenuSelectionManager
                .defaultManager()
                .getSelectedPath();
        if(elems != null && elems.length != 0) {
            return false;
            // We shall not interfere with already opened menu
        }

        Component c = KeyboardFocusManager
               .getCurrentKeyboardFocusManager()
                .getFocusOwner();
        if(c instanceof JComponent) {
            JComponent src = (JComponent) c;
            return src.getComponentPopupMenu() != null;
        }

        return false;
    }

    if (sender != null && sender instanceof JRootPane) {
        JButton owner = ((JRootPane)sender).getDefaultButton();
        return (owner != null && owner.getModel().isEnabled());
    }
    return true;
}
 
Example 44
Project: incubator-netbeans   File: J2SEPlatformCustomizer.java   Source Code and License 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Icon icon = null;
    if (value instanceof URL) {
        Pair<String,Icon> p = getDisplayName((URL)value);
        value = p.first();
        icon = p.second();
    }
    final Component res = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    setIcon(icon);
    return res;
}
 
Example 45
Project: openjdk-jdk10   File: JOptionPane.java   Source Code and License 5 votes vote down vote up
private static boolean checkFrameForComponent(Component parentComponent) {
    if (parentComponent == null) {
        return false;
    }
    if (parentComponent instanceof Frame) {
        return true;
    }
    return checkFrameForComponent(parentComponent.getParent());
}
 
Example 46
Project: Equella   File: ExpressionTableCellRenderer.java   Source Code and License 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
	int row, int column)
{
	super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	try
	{
		setText(formatter.convertToInfix((String) value));
	}
	catch( Exception ex )
	{
		setText(INVALID_EXPRESSION);
	}
	return this;
}
 
Example 47
Project: jmt   File: ExactTable.java   Source Code and License 5 votes vote down vote up
private void sizeColumns() {
	/* try and resize columns according to their header and (if available) prototype width*/
	/* taken from Sun's JTable tutorial, with some added features */
	int colnum = dataModel.getColumnCount();
	TableColumn col;
	Component comp;
	PrototypedTableModel ptm = null;
	boolean hasPrototypes = false;
	int autoWidth;

	if (dataModel instanceof PrototypedTableModel) {
		hasPrototypes = true;
		ptm = (PrototypedTableModel) dataModel;
	}

	if (tableHeader == null) {
		return; // hack: skip column sizing until we actually have a header
	}

	for (int i = 0; i < colnum; i++) {
		col = columnModel.getColumn(i);

		comp = tableHeader.getDefaultRenderer().getTableCellRendererComponent(null, col.getHeaderValue(), false, false, 0, i);
		autoWidth = comp.getPreferredSize().width;

		if (hasPrototypes) {
			//comp = getDefaultRenderer(dataModel.getColumnClass(i)).getTableCellRendererComponent(this, ptm.getPrototype(i), false, false, 0, i);
			comp = getDefaultRenderer(Object.class).getTableCellRendererComponent(this, ptm.getPrototype(i), false, false, 0, i);
			autoWidth = Math.max(autoWidth, comp.getPreferredSize().width);
		}

		col.setPreferredWidth(autoWidth);
	}
}
 
Example 48
Project: Equella   File: ExportAction.java   Source Code and License 5 votes vote down vote up
public <T> void writeFile(Component parent, final File destination, final ExportSerialiser getter)
{
	GlassSwingWorker<?> worker = new GlassSwingWorker<Object>()
	{
		@Override
		public Object construct() throws Exception
		{
			try( Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destination),
				Constants.UTF8)) )
			{
				out.write(getter.getSerialisedForm());
			}
			return null;
		}

		@Override
		public void finished()
		{
			Driver.displayInformation(getComponent(),
				CurrentLocale.get("com.tle.admin.gui.common.actions.exportaction.successful")); //$NON-NLS-1$
		}

		@Override
		public void exception()
		{
			Driver.displayInformation(getComponent(),
				CurrentLocale.get("com.tle.admin.gui.common.actions.exportaction.error")); //$NON-NLS-1$
			getException().printStackTrace();
		}
	};

	worker.setComponent(parent);
	worker.start();
}
 
Example 49
Project: jdk8u-jdk   File: SunVolatileImage.java   Source Code and License 5 votes vote down vote up
private SunVolatileImage(Component comp,
                         GraphicsConfiguration graphicsConfig,
                         int width, int height, Object context,
                         ImageCapabilities caps)
{
    this(comp, graphicsConfig,
         width, height, context, Transparency.OPAQUE, caps, UNDEFINED);
}
 
Example 50
Project: openjdk-jdk10   File: CAccessibleText.java   Source Code and License 5 votes vote down vote up
static int[] getRangeForLine(final Accessible a, final Component c, final int line) {
    if (a == null) return null;
    return CAccessibility.invokeAndWait(new Callable<int[]>() {
        public int[] call() {
            return getRangeForLine(a, line);
        }
    }, c);
}
 
Example 51
Project: incubator-netbeans   File: ETable.java   Source Code and License 5 votes vote down vote up
/**
 * Checks whether the given component is "our".
 */
private boolean isKnownComponent(Component c) {
    if (c == null) return false;
    if (isAncestorOf (c)) {
        return true;
    }
    if (c == editorComp) {
        return true;
    }
    if (editorComp != null && (editorComp instanceof Container) &&
        ((Container) editorComp).isAncestorOf(c)) {
            return true;
    }
    return false;
}
 
Example 52
Project: incubator-netbeans   File: DropdownButton.java   Source Code and License 5 votes vote down vote up
public void setIcon(Icon icon) {
    if (button != null) {
        Icon _icon = button.getIcon();
        button.setIcon(icon);
        
        Component parent = getParent();
        if (!Objects.equals(icon, _icon) && parent != null) {
            parent.invalidate();
            parent.revalidate();
            parent.repaint();
        }
    }
}
 
Example 53
Project: incubator-netbeans   File: EditableDisplayerTest.java   Source Code and License 5 votes vote down vote up
/** Asserts that a pixel at a given position in an image matches a
 * pixel in a given position in a component */
private synchronized void assertPixelFromImage(String msg, final Image i, final Component c, final int imageX, final int imageY, final int compX, final int compY) throws Exception {
    final BufferedImage bi = i instanceof BufferedImage ? (BufferedImage) i : toBufferedImage(i);
    throwMe = null;
    sleep();
    
    int rgb = bi.getRGB(imageX, imageY);
    Color color = new Color(rgb);
    
    
    //uncomment the code below for diagnosing painting problems
    //and seeing which pixel you'return really checking
    JFrame jf = new JFrame("assertPixelFromImage " + count + " (look for the yellow line)") {
        public void paint(Graphics g) {
            new ImageIcon(bi).paintIcon(this, g, 25, 25);
            g.setColor(Color.YELLOW);
            g.drawLine(imageX+20, imageY+25, imageX+25, imageY+25);
        }
    };
    jf.setLocation(500,500);
    jf.setSize(100,100);
    jf.show();
    
    try {
        assertPixel(msg, c, color, compX, compY);
    } catch (Exception e) {
        throwMe = e;
    }
    if (throwMe != null) {
        throw throwMe;
    }
}
 
Example 54
Project: jdk8u-jdk   File: LegacyGlueFocusTraversalPolicy.java   Source Code and License 5 votes vote down vote up
public Component getComponentAfter(Container focusCycleRoot,
                                   Component aComponent) {
    Component hardCoded = aComponent, prevHardCoded;
    HashSet<Component> sanity = new HashSet<Component>();

    do {
        prevHardCoded = hardCoded;
        hardCoded = forwardMap.get(hardCoded);
        if (hardCoded == null) {
            if (delegatePolicy != null &&
                prevHardCoded.isFocusCycleRoot(focusCycleRoot)) {
                return delegatePolicy.getComponentAfter(focusCycleRoot,
                                                        prevHardCoded);
            } else if (delegateManager != null) {
                return delegateManager.
                    getComponentAfter(focusCycleRoot, aComponent);
            } else {
                return null;
            }
        }
        if (sanity.contains(hardCoded)) {
            // cycle detected; bail
            return null;
        }
        sanity.add(hardCoded);
    } while (!accept(hardCoded));

    return hardCoded;
}
 
Example 55
Project: KernelHive   File: MessageDialog.java   Source Code and License 5 votes vote down vote up
public static void showMessageDialog(Component parent, String title, String message){
	JOptionPane
	.showMessageDialog(
			parent,
			message,
			title,
			JOptionPane.INFORMATION_MESSAGE,
			new ImageIcon(
					MessageDialog.class
							.getResource("/com/sun/java/swing/plaf/windows/icons/Inform.gif")));
}
 
Example 56
Project: incubator-netbeans   File: FormI18nMnemonicEditor.java   Source Code and License 4 votes vote down vote up
/** Overrides superclass method.
 * @return <code>ResourceBundlePanel</code> fed with <code>FormI18nMnemonic</code> value. */
@Override
public Component getCustomEditor() {
    return new CustomEditor(new FormI18nMnemonic((FormI18nMnemonic)getValue()), getProject(), sourceDataObject.getPrimaryFile());
}
 
Example 57
Project: hy.common.ui   File: JCheckBoxEditor.java   Source Code and License 4 votes vote down vote up
public Component getTableCellEditorComponent(JTable  i_Table
		                                    ,Object  i_Value
		                                    ,boolean i_IsSelected
		                                    ,int     i_Row
		                                    ,int     i_Column) 
{
	if ( i_Value == null )
	{
		if ( this.jcheckbox == null )
		{
			this.jcheckbox = new JCheckBox();
		}
	}
	else if ( i_Value instanceof JCheckBox )
	{
		this.jcheckbox = (JCheckBox)i_Value;
	}
	else if ( i_Value instanceof Boolean )
	{
		if ( this.jcheckbox == null )
		{
			this.jcheckbox = new JCheckBox();
		}
		
		if ( ((Boolean)i_Value).booleanValue() )
		{
			this.jcheckbox.setSelected(true);
		}
		else
		{
			this.jcheckbox.setSelected(false);
		}
	}
	else
	{
		if ( this.jcheckbox == null )
		{
			this.jcheckbox = new JCheckBox();
		}
		
		this.jcheckbox.setSelected(false);
	}
	
	this.jcheckbox.addItemListener(this);
	
	return (Component)this.jcheckbox;
}
 
Example 58
Project: ramus   File: ExportToImagesDialog.java   Source Code and License 4 votes vote down vote up
private Component createBottomPanel() {
    double[][] size = {
            {5, TableLayout.MINIMUM, 5, TableLayout.FILL, 5,
                    TableLayout.MINIMUM, 5},
            {5, TableLayout.MINIMUM, 5, TableLayout.MINIMUM, 5,
                    TableLayout.MINIMUM, 5}};

    JPanel panel = new JPanel(new TableLayout(size));

    imageSizeComboBox = new JComboBox();
    imageSizeComboBox.addItem("799x530");
    imageSizeComboBox.addItem("904x601");
    imageSizeComboBox.addItem("1023x680");
    imageSizeComboBox.addItem("1151x765");
    imageSizeComboBox.addItem("1299x864");
    imageSizeComboBox.addItem("1600x1064");

    imageTypeComboBox = new JComboBox();
    imageTypeComboBox.addItem(".bmp");
    imageTypeComboBox.addItem(".png");
    imageTypeComboBox.addItem(".jpg");
    imageTypeComboBox.addItem(".svg");
    imageTypeComboBox.addItem(".emf");
    imageTypeComboBox.setSelectedIndex(1);

    panel.add(new JLabel(ResourceLoader.getString("ImageSize")), "1,1");
    panel.add(imageSizeComboBox, "3,1,5,1");

    panel.add(new JLabel(ResourceLoader.getString("ImageType")), "1,3");
    panel.add(imageTypeComboBox, "3,3,5,3");

    panel.add(new Label(ResourceLoader.getString("Folder")), "1, 5");
    panel.add(directory, "3, 5");
    panel.add(new JButton(new AbstractAction(GlobalResourcesManager
            .getString("Action.Browse")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setSelectedFile(new File(directory.getText()));
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int r = fileChooser.showOpenDialog(null);
            if (r == JFileChooser.APPROVE_OPTION)
                directory.setText(fileChooser.getSelectedFile()
                        .getAbsolutePath());
        }
    }), "5, 5");

    return panel;
}
 
Example 59
Project: openjdk-jdk10   File: XComponentPeer.java   Source Code and License 4 votes vote down vote up
/**
 * Standard peer constructor, with corresponding Component
 */
XComponentPeer(Component target) {
    super(target);
}
 
Example 60
Project: Kids-Learning-Software   File: FocusTraversalOnArray.java   Source Code and License 4 votes vote down vote up
public Component getFirstComponent(Container container) {
	return m_Components[0];
}