Search in sources :

Example 41 with GridBagLayout

use of java.awt.GridBagLayout in project OpenNotebook by jaltekruse.

the class ColorAdjustmentPanel method addPanelContent.

@Override
public void addPanelContent() {
    setLayout(new GridBagLayout());
    if (mAtt.getName().equals(MathObject.FILL_COLOR)) {
        checkbox = new JCheckBox("fill");
        if (mAtt.getValue() != null)
            checkbox.setSelected(true);
        else
            checkbox.setSelected(false);
        checkbox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (justChangedColor) {
                        justChangedColor = false;
                        return;
                    }
                    if (mAtt.getValue() == null) {
                        mAtt.setValue(Color.WHITE);
                    }
                    colorLabel.setBackground(mAtt.getValue());
                    ColorAdjustmentPanel.this.repaint();
                    notebookPanel.getCurrentDocViewer().addUndoState();
                    notebookPanel.getCurrentDocViewer().repaintDoc();
                    notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
                } else {
                    mAtt.setValue(null);
                    colorLabel.setBackground(mAtt.getValue());
                    ColorAdjustmentPanel.this.repaint();
                    notebookPanel.getCurrentDocViewer().addUndoState();
                    notebookPanel.getCurrentDocViewer().repaintDoc();
                    notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
                }
            }
        });
    }
    colorLabel = new JLabel("    ");
    colorLabel.setBorder(new LineBorder(Color.BLACK));
    colorLabel.setOpaque(true);
    colorLabel.setBackground(mAtt.getValue());
    colorLabel.addMouseListener(new MouseListener() {

        public void mouseClicked(MouseEvent arg0) {
        }

        public void mouseEntered(MouseEvent arg0) {
        }

        public void mouseExited(MouseEvent arg0) {
        }

        public void mousePressed(MouseEvent arg0) {
            Color c = JColorChooser.showDialog(ColorAdjustmentPanel.this, "Choose color", ((ColorAttribute) mAtt).getValue());
            ((ColorAttribute) mAtt).setValue(c);
            colorLabel.setBackground(mAtt.getValue());
            if (checkbox != null) {
                if (((ColorAttribute) mAtt).getValue() != null) {
                    justChangedColor = true;
                    checkbox.setSelected(true);
                } else {
                    checkbox.setSelected(false);
                }
            }
            notebookPanel.getCurrentDocViewer().addUndoState();
            notebookPanel.getCurrentDocViewer().repaintDoc();
        }

        public void mouseReleased(MouseEvent arg0) {
        }
    });
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.HORIZONTAL;
    con.weightx = 1;
    con.gridx = 0;
    con.gridy = 0;
    con.insets = new Insets(0, 0, 0, 3);
    if (mAtt.getName().equals(MathObject.FILL_COLOR)) {
        add(checkbox, con);
    } else {
        add(new JLabel(mAtt.getName()), con);
    }
    con.gridy = 0;
    con.gridx = 1;
    con.gridheight = 1;
    add(colorLabel, con);
//		con.gridx = 2;
//		add(setColor, con);
}
Also used : ItemEvent(java.awt.event.ItemEvent) GridBagConstraints(java.awt.GridBagConstraints) MouseEvent(java.awt.event.MouseEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) LineBorder(javax.swing.border.LineBorder) Color(java.awt.Color) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) MouseListener(java.awt.event.MouseListener) ItemListener(java.awt.event.ItemListener) ColorAttribute(doc.attributes.ColorAttribute)

Example 42 with GridBagLayout

use of java.awt.GridBagLayout in project OpenNotebook by jaltekruse.

the class EnumeratedAdjuster method addPanelContent.

@Override
public void addPanelContent() {
    if (displayFormat == COMBO_BOX) {
        setLayout(new GridBagLayout());
        GridBagConstraints con = new GridBagConstraints();
        con.fill = GridBagConstraints.HORIZONTAL;
        con.weightx = .1;
        con.gridx = 0;
        con.gridy = 0;
        con.insets = new Insets(0, 10, 0, 0);
        add(new JLabel(mAtt.getName()), con);
        con.insets = new Insets(0, 10, 0, 5);
        con.weightx = 1;
        con.gridx = 1;
        final JComboBox valueChoices = new JComboBox(mAtt.getPossibleValues());
        valueChoices.setSelectedItem(mAtt.getValue());
        valueChoices.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ev) {
                mAtt.setValue((String) valueChoices.getSelectedItem());
                if (notebookPanel != null) {
                    notebookPanel.getCurrentDocViewer().addUndoState();
                    notebookPanel.getCurrentDocViewer().repaintDoc();
                }
            }
        });
        this.add(valueChoices, con);
    } else if (displayFormat == RADIO_BUTTON_ROW) {
        setLayout(new GridBagLayout());
        GridBagConstraints con = new GridBagConstraints();
        con.fill = GridBagConstraints.HORIZONTAL;
        con.weightx = .1;
        con.gridwidth = mAtt.getPossibleValues().length;
        con.gridx = 0;
        con.gridy = 0;
        con.insets = new Insets(2, 2, 2, 2);
        Font f = new Font("Arial", Font.PLAIN, 12);
        Font smallF = new Font("Arial", Font.PLAIN, 11);
        JLabel label = new JLabel(mAtt.getName());
        label.setFont(f);
        add(label, con);
        con.gridwidth = 1;
        con.weightx = 1;
        con.gridy++;
        final ButtonGroup group = new ButtonGroup();
        for (final String s : mAtt.getPossibleValues()) {
            final JRadioButton button = new JRadioButton(s);
            button.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent ev) {
                    mAtt.setValue(s);
                    if (notebookPanel != null) {
                        notebookPanel.getCurrentDocViewer().addUndoState();
                        notebookPanel.getCurrentDocViewer().repaintDoc();
                    }
                }
            });
            if (mAtt.getValue().equals(s)) {
                button.setSelected(true);
            }
            button.setFont(smallF);
            this.add(button, con);
            group.add(button);
            con.gridx++;
        }
    } else if (displayFormat == RADIO_BUTTON_COLOUMN) {
    }
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) Font(java.awt.Font)

Example 43 with GridBagLayout

use of java.awt.GridBagLayout in project OpenNotebook by jaltekruse.

the class GenericAdjustmentPanel method addPanelContent.

@Override
public void addPanelContent() {
    setLayout(new GridBagLayout());
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.HORIZONTAL;
    con.weightx = .1;
    con.gridx = 0;
    con.gridy = 0;
    con.insets = new Insets(0, 5, 0, 5);
    add(new JLabel(mAtt.getName()), con);
    field = new JTextField();
    con.weightx = 1;
    con.gridx = 1;
    con.insets = new Insets(0, 0, 0, 0);
    add(field, con);
    if (mAtt.getValue() instanceof Double) {
        int len = mAtt.getValue().toString().length();
        if (len > 5) {
            formatter = new Formatter();
            field.setText(String.format("%.5G", mAtt.getValue()));
        }
    } else {
        if (mAtt.getValue() == null) {
            field.setText("");
        } else
            field.setText(mAtt.getValue().toString());
    }
    field.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent arg0) {
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            try {
                if (mAtt.getParentObject() != null) {
                    mAtt.getParentObject().setAttributeValueWithString(mAtt.getName(), field.getText());
                } else {
                    mAtt.setValueWithString(field.getText());
                }
                if (notebookPanel != null) {
                    notebookPanel.getCurrentDocViewer().repaintDoc();
                    notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
                }
            } catch (AttributeException e) {
                if (!showingDialog) {
                    JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                    showingDialog = false;
                }
            }
        }
    });
    field.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            applyPanelValueToObject();
        }
    });
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Formatter(java.util.Formatter) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) AttributeException(doc.attributes.AttributeException) ActionListener(java.awt.event.ActionListener) FocusListener(java.awt.event.FocusListener)

Example 44 with GridBagLayout

use of java.awt.GridBagLayout in project OpenNotebook by jaltekruse.

the class ObjectPropertiesFrame method generatePanel.

/**
	 * Generates a menu for adjusting the properties of a mathobject.
	 * 
	 * @param o - object to base menu panel on
	 */
public void generatePanel(MathObject o) {
    System.out.println("generate panel" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (o == null) {
        return;
    }
    this.getContentPane().removeAll();
    object = o;
    JPanel panel = mainPanel;
    mainPanel.removeAll();
    adjusters.removeAllElements();
    listAdjusters.removeAllElements();
    this.setTitle(o.getType());
    JTabbedPane panelTabs = null;
    JPanel tabOneContents = null, tabTwoContents = null;
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.BOTH;
    con.weightx = 1;
    con.weighty = 1;
    con.insets = new Insets(2, 2, 2, 2);
    con.gridx = 0;
    con.gridy = 0;
    System.out.println("end init stuff" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (o instanceof GraphObject || (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())) {
        // there are too many attributes and actions for the graph to put them all in one panel
        // add a tabbed pane to make it more reasonable and avoid scrolling
        panelTabs = new JTabbedPane();
        this.getContentPane().add(panelTabs);
        tabOneContents = new JPanel();
        tabOneContents.setLayout(new GridBagLayout());
        tabTwoContents = new JPanel();
        tabTwoContents.setLayout(new GridBagLayout());
        System.out.println("1 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        JScrollPane tabScrollPane = new JScrollPane(panelTabs);
        tabScrollPane.getVerticalScrollBar().setUnitIncrement(16);
        tabScrollPane.getHorizontalScrollBar().setUnitIncrement(16);
        System.out.println("2 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        tabScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        if (o instanceof GraphObject) {
            panelTabs.add("Nav", tabOneContents);
            panelTabs.add("Grid", tabTwoContents);
            panel = tabOneContents;
        } else if (o instanceof ExpressionObject) {
            panelTabs.add("Expression", tabOneContents);
            panelTabs.add("Solve", tabTwoContents);
            panel = tabOneContents;
        }
        System.out.println("3 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        this.getContentPane().add(tabScrollPane);
        System.out.println("4 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    } else {
        this.getContentPane().add(scrollPane);
    }
    System.out.println("done with tabs " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    con.weighty = .01;
    JPanel actionPics = new JPanel();
    actionPics.setLayout(new GridLayout(0, 4, 4, 4));
    JPanel otherActions = new JPanel();
    otherActions.setLayout(new GridLayout(0, 1, 4, 4));
    ImageIcon pic;
    JButton button;
    if (!notebookPanel.isInStudentMode()) {
        for (final String s : o.getActions()) {
            pic = getIconForAction(s);
            if (pic != null)
                createButton(s, 0, 0, 0, 0, actionPics);
            else
                createButton(s, 0, 0, 0, 0, otherActions);
        }
    }
    System.out.println("teacher actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    boolean skipAction;
    for (final String s : o.getStudentActions()) {
        skipAction = false;
        if (object instanceof GraphObject) {
            // use more intuitive
            for (String str : graphNavActions) {
                if (s.equals(str)) {
                    skipAction = true;
                    break;
                }
            }
        }
        if (object instanceof ExpressionObject) {
            // in a separate panel to make the list of actions smaller
            for (String str : expressionOpActions) {
                if (s.equals(str)) {
                    skipAction = true;
                    break;
                }
            }
        }
        if (skipAction) {
            continue;
        }
        pic = getIconForAction(s);
        if (pic != null)
            createButton(s, 0, 0, 0, 0, actionPics);
        else
            createButton(s, 0, 0, 0, 0, otherActions);
    }
    System.out.println("student actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (otherActions.getComponentCount() != 0) {
        // only add panel for actions if components have been added to it
        panel.add(otherActions, con);
        con.gridy++;
    }
    if (actionPics.getComponentCount() != 0) {
        // only add panel for action pics if components have been added to it
        panel.add(actionPics, con);
        con.gridy++;
    }
    if (object instanceof GraphObject) {
        panel.add(createGraphNavigator(), con);
        con.gridy++;
    }
    if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode()) {
        // there are too many attributes and actions for the expression to put them all in one panel
        // added a tabbed pane to make it more reasonable and avoid scrolling
        // this line moves to the other tab to place components there
        panel = tabTwoContents;
    }
    if (object instanceof ExpressionObject) {
        panel.add(createExpressionModifier(), con);
        con.gridy++;
    }
    //Switch back to tab one if in teacher mode, to allow attribute adjusters to be on the first tab
    if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())
        panel = tabOneContents;
    con.fill = GridBagConstraints.HORIZONTAL;
    if (o instanceof GraphObject) {
        // there are too many attributes and actions for the graph to put them all in one panel
        // added a tabbed pane to make it more reasonable and avoid scrolling
        // this line moves to the other tab to place components there
        panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        con.anchor = GridBagConstraints.PAGE_START;
        tabTwoContents.add(panel, con);
        con.anchor = GridBagConstraints.CENTER;
    }
    con.fill = GridBagConstraints.BOTH;
    for (MathObjectAttribute mAtt : o.getAttributes()) {
        if (notebookPanel.isInStudentMode() && mAtt.isStudentEditable() || (!notebookPanel.isInStudentMode() && mAtt.isUserEditable())) {
            // only show editing dialog if in teacher mode (not student)
            //or if the attribute has been left student editable
            adjusters.add(getAdjuster(mAtt, notebookPanel, panel));
            if (mAtt instanceof StringAttribute) {
                // make string panels stretch vertically
                con.weighty = 1;
                con.fill = GridBagConstraints.BOTH;
            } else {
                // make all others stretch very little vertically
                con.weighty = 0;
                con.fill = GridBagConstraints.HORIZONTAL;
            }
            panel.add(adjusters.get(adjusters.size() - 1), con);
            con.gridy++;
        }
    }
    System.out.println("end att adjusters:" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    con.weighty = 1;
    if (o instanceof GraphObject) {
        // see above comments about tabs for some objects
        panel = tabOneContents;
    }
    for (ListAttribute list : o.getLists()) {
        if ((notebookPanel.isInStudentMode() && list.isStudentEditable()) || (!notebookPanel.isInStudentMode() && list.isUserEditable())) {
            // only show editing dialog if in teacher mode (not student)
            //or if the attribute has been left student editable
            listAdjusters.add(new ListAdjuster(list, notebookPanel, panel));
            panel.add(listAdjusters.get(listAdjusters.size() - 1), con);
            con.gridy++;
        }
    }
    System.out.println("end lists:" + +(new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (panel.getComponentCount() == 0) {
        panel.add(new JLabel("No actions for this object"), con);
    }
    panel.revalidate();
    this.pack();
    this.update();
    this.setSize(this.getWidth() + 30, this.getHeight());
    System.out.println("done making props frame" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) StringAttribute(doc.attributes.StringAttribute) JLabel(javax.swing.JLabel) GraphObject(doc.mathobjects.GraphObject) Date(java.util.Date) GridLayout(java.awt.GridLayout) MathObjectAttribute(doc.attributes.MathObjectAttribute) ExpressionObject(doc.mathobjects.ExpressionObject) ListAttribute(doc.attributes.ListAttribute)

Example 45 with GridBagLayout

use of java.awt.GridBagLayout in project OpenNotebook by jaltekruse.

the class ObjectPropertiesFrame method createExpressionModifier.

private JPanel createExpressionModifier() {
    JPanel newPanel = new JPanel();
    newPanel.setLayout(new GridBagLayout());
    ImageIcon pic;
    new OCButton(ExpressionObject.SUB_IN_VALUE, 4, 1, 0, 0, newPanel) {

        public void associatedAction() {
            buttonAction(ExpressionObject.SUB_IN_VALUE);
        }
    };
    new OCButton(ExpressionObject.MODIFY_EXPRESSION, 4, 1, 0, 1, newPanel) {

        public void associatedAction() {
            buttonAction(ExpressionObject.MODIFY_EXPRESSION);
        }
    };
    new OCButton(ExpressionObject.MANUALLY_TYPE_STEP, 4, 1, 0, 2, newPanel) {

        public void associatedAction() {
            buttonAction(ExpressionObject.MANUALLY_TYPE_STEP);
        }
    };
    new OCButton(ExpressionObject.UNDO_STEP, 4, 1, 0, 3, newPanel) {

        public void associatedAction() {
            buttonAction(ExpressionObject.UNDO_STEP);
        }
    };
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.HORIZONTAL;
    con.gridx = 0;
    con.gridy = 4;
    con.gridwidth = 4;
    con.weightx = 1;
    con.weighty = .02;
    newPanel.add(new JLabel("Apply to both sides"), con);
    createButton(ExpressionObject.ADD_TO_BOTH_SIDES, 1, 1, 0, 5, newPanel);
    createButton(ExpressionObject.SUBTRACT_FROM_BOTH_SIDES, 1, 1, 1, 5, newPanel);
    createButton(ExpressionObject.MULTIPLY_BOTH_SIDES, 1, 1, 2, 5, newPanel);
    createButton(ExpressionObject.DIVIDE_BOTH_SIDES, 1, 1, 3, 5, newPanel);
    new OCButton(ExpressionObject.OTHER_OPERATIONS, 4, 1, 0, 6, newPanel) {

        public void associatedAction() {
            buttonAction(ExpressionObject.OTHER_OPERATIONS);
        }
    };
    return newPanel;
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) OCButton(doc_gui.OCButton) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel)

Aggregations

GridBagLayout (java.awt.GridBagLayout)739 GridBagConstraints (java.awt.GridBagConstraints)576 JPanel (javax.swing.JPanel)532 JLabel (javax.swing.JLabel)425 Insets (java.awt.Insets)409 Dimension (java.awt.Dimension)182 JScrollPane (javax.swing.JScrollPane)147 JButton (javax.swing.JButton)143 ActionEvent (java.awt.event.ActionEvent)136 ActionListener (java.awt.event.ActionListener)115 JTextField (javax.swing.JTextField)100 BorderLayout (java.awt.BorderLayout)96 JCheckBox (javax.swing.JCheckBox)79 BoxLayout (javax.swing.BoxLayout)66 ButtonGroup (javax.swing.ButtonGroup)56 TitledBorder (javax.swing.border.TitledBorder)48 JComboBox (javax.swing.JComboBox)46 FlowLayout (java.awt.FlowLayout)42 JRadioButton (javax.swing.JRadioButton)36 Color (java.awt.Color)34