Search in sources :

Example 81 with JComponent

use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.

the class TSFrame method createGui.

public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
    Frame frame;
    done = false;
    if (useNonOpaque) {
        if (useSwing) {
            frame = new NonOpaqueJFrame();
        //                frame = new NonOpaqueJAppletFrame(gc);
        } else {
            frame = new NonOpaqueFrame();
        }
        animateComponent(frame);
    } else if (useSwing) {
        frame = new JFrame("Swing Frame");
        JComponent p = new JButton("Swing!");
        p.setPreferredSize(new Dimension(200, 100));
        frame.add("North", p);
        p = new MyJPanel();
        animateComponent(p);
        frame.add("Center", p);
    } else {
        frame = new Frame("AWT Frame") {

            public void paint(Graphics g) {
                g.setColor(Color.red);
                g.fillRect(0, 0, 100, 100);
            }
        };
        frame.setLayout(new BorderLayout());
        Canvas c = new MyCanvas();
        frame.add("North", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("Center", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("South", c);
        animateComponent(c);
    }
    final Frame finalFrame = frame;
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.setPreferredSize(new Dimension(800, 600));
    if (useShape) {
        frame.setUndecorated(true);
    }
    frame.setLocation(450, 10);
    frame.pack();
    GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
    if (useShape) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
            System.out.println("applying PERPIXEL_TRANSPARENT");
            frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
            frame.setTitle("PERPIXEL_TRANSPARENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
        }
    }
    if (useTransl) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
            System.out.println("applying TRANSLUCENT");
            frame.setOpacity(factor);
            frame.setTitle("TRANSLUCENT");
        } else {
            System.out.println("Passed: TRANSLUCENT unsupported");
        }
    }
    if (useNonOpaque) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
            System.out.println("applying PERPIXEL_TRANSLUCENT");
            frame.setBackground(new Color(0, 0, 0, 0));
            frame.setTitle("PERPIXEL_TRANSLUCENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
        }
    }
    frame.setVisible(true);
    return frame;
}
Also used : JFrame(javax.swing.JFrame) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) Canvas(java.awt.Canvas) Color(java.awt.Color) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) MouseAdapter(java.awt.event.MouseAdapter) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) Ellipse2D(java.awt.geom.Ellipse2D) Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

Example 82 with JComponent

use of javax.swing.JComponent in project processdash by dtuma.

the class DataTableCellNumericRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    NumericDataValue number = (NumericDataValue) value;
    String display = "";
    String errorMsg = null;
    boolean readOnly = false;
    Color errorColor = null;
    if (number != null) {
        // extract information from the NumericDataValue object.
        display = number.isInvisible ? "" : formatNumber(number);
        errorMsg = number.errorMessage;
        errorColor = number.errorColor;
        readOnly = (number.isEditable == false);
    }
    // ask our superclass for an appropriate renderer component.
    Component result = super.getTableCellRendererComponent(table, display, isSelected, hasFocus, row, column);
    // change the foreground color for read-only or erroneous values.
    result.setForeground(getForegroundColor(errorMsg, errorColor, readOnly));
    // use a bold font for erroneous values.
    Font f = getFont(errorMsg != null, result);
    if (f != null)
        result.setFont(f);
    if (result instanceof JComponent)
        // set or remove a descriptive tooltip
        ((JComponent) result).setToolTipText(errorMsg);
    return result;
}
Also used : Color(java.awt.Color) JComponent(javax.swing.JComponent) JComponent(javax.swing.JComponent) Component(java.awt.Component) Font(java.awt.Font)

Example 83 with JComponent

use of javax.swing.JComponent in project processdash by dtuma.

the class BoundForm method addFormElement.

protected void addFormElement(Object element, Element xml) {
    super.addFormElement(element, xml);
    if (element instanceof JComponent) {
        JComponent component = (JComponent) element;
        addFormComponent(component, xml);
    }
}
Also used : JComponent(javax.swing.JComponent)

Example 84 with JComponent

use of javax.swing.JComponent in project cayenne by apache.

the class ObjEntityRelationshipPanel method rebuildTable.

protected void rebuildTable(ObjEntity entity) {
    final ObjRelationshipTableModel model = new ObjRelationshipTableModel(entity, mediator, this);
    model.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (table.getSelectedRow() >= 0) {
                ObjRelationship rel = model.getRelationship(table.getSelectedRow());
                enabledResolve = rel.getSourceEntity().getDbEntity() != null;
                resolveMenu.setEnabled(enabledResolve);
            }
        }
    });
    table.setModel(model);
    table.setRowHeight(25);
    table.setRowMargin(3);
    TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET_PATH);
    col.setCellEditor(new DbRelationshipPathComboBoxEditor());
    col.setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
            setToolTipText("To choose relationship press enter two times.To choose next relationship press dot.");
            return this;
        }
    });
    col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_DELETE_RULE);
    JComboBox deleteRulesCombo = Application.getWidgetFactory().createComboBox(DELETE_RULES, false);
    deleteRulesCombo.setFocusable(false);
    deleteRulesCombo.setEditable(true);
    ((JComponent) deleteRulesCombo.getEditor().getEditorComponent()).setBorder(null);
    deleteRulesCombo.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
    // Default to the first value
    deleteRulesCombo.setSelectedIndex(0);
    col.setCellEditor(Application.getWidgetFactory().createCellEditor(deleteRulesCombo));
    tablePreferences.bind(table, null, null, null, ObjRelationshipTableModel.REL_NAME, true);
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbRelationshipPathComboBoxEditor(org.apache.cayenne.modeler.util.DbRelationshipPathComboBoxEditor) JComboBox(javax.swing.JComboBox) TableModelEvent(javax.swing.event.TableModelEvent) JComponent(javax.swing.JComponent) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableModelListener(javax.swing.event.TableModelListener) JTable(javax.swing.JTable) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 85 with JComponent

use of javax.swing.JComponent in project cayenne by apache.

the class ComboSelectionBinding method initComponentDefaults.

protected void initComponentDefaults() {
    this.errorColor = ValidatorDialog.WARNING_COLOR;
    if (comboBox.getEditor() != null) {
        Component editor = comboBox.getEditor().getEditorComponent();
        if (editor instanceof JComponent) {
            JComponent jEditor = (JComponent) editor;
            this.defaultBGColor = jEditor.getBackground();
            this.defaultToolTip = jEditor.getToolTipText();
        }
    }
}
Also used : JComponent(javax.swing.JComponent) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

JComponent (javax.swing.JComponent)225 Component (java.awt.Component)44 JPanel (javax.swing.JPanel)37 JLabel (javax.swing.JLabel)34 JButton (javax.swing.JButton)28 BorderLayout (java.awt.BorderLayout)27 Dimension (java.awt.Dimension)23 Insets (java.awt.Insets)20 ActionEvent (java.awt.event.ActionEvent)16 ArrayList (java.util.ArrayList)16 ActionListener (java.awt.event.ActionListener)15 Color (java.awt.Color)13 GridBagConstraints (java.awt.GridBagConstraints)13 Point (java.awt.Point)13 GridBagLayout (java.awt.GridBagLayout)12 JScrollPane (javax.swing.JScrollPane)12 JTextField (javax.swing.JTextField)12 JFrame (javax.swing.JFrame)11 Container (java.awt.Container)8 FlowLayout (java.awt.FlowLayout)8