Example usage for java.awt GridBagConstraints REMAINDER

List of usage examples for java.awt GridBagConstraints REMAINDER

Introduction

In this page you can find the example usage for java.awt GridBagConstraints REMAINDER.

Prototype

int REMAINDER

To view the source code for java.awt GridBagConstraints REMAINDER.

Click Source Link

Document

Specifies that this component is the last component in its column or row.

Usage

From source file:TextSamplerDemo.java

private void addLabelTextRows(JLabel[] labels, JTextField[] textFields, GridBagLayout gridbag,
        Container container) {/* w  w w  .  j av a 2  s . c  o m*/
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.EAST;
    int numLabels = labels.length;

    for (int i = 0; i < numLabels; i++) {
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.NONE; //reset to default
        c.weightx = 0.0; //reset to default
        container.add(labels[i], c);

        c.gridwidth = GridBagConstraints.REMAINDER; //end row
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 1.0;
        container.add(textFields[i], c);
    }
}

From source file:org.executequery.gui.browser.ConnectionPanel.java

private void init() {

    // ---------------------------------
    // create the basic props panel

    // initialise the fields
    nameField = createTextField();/*from w w w .  j  a v  a 2s .  c om*/
    passwordField = createPasswordField();
    hostField = createTextField();
    portField = createNumberTextField();
    sourceField = createMatchedWidthTextField();
    userField = createTextField();
    urlField = createMatchedWidthTextField();

    nameField.addFocusListener(new ConnectionNameFieldListener(this));

    savePwdCheck = ActionUtilities.createCheckBox("Store Password", "setStorePassword");
    encryptPwdCheck = ActionUtilities.createCheckBox("Encrypt Password", "setEncryptPassword");

    savePwdCheck.addActionListener(this);
    encryptPwdCheck.addActionListener(this);

    // retrieve the drivers
    buildDriversList();

    // ---------------------------------
    // add the basic connection fields

    TextFieldPanel mainPanel = new TextFieldPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.insets = new Insets(10, 10, 10, 10);
    gbc.gridy = 0;
    gbc.gridx = 0;

    statusLabel = new DefaultFieldLabel();
    addLabelFieldPair(mainPanel, "Status:", statusLabel, "Current connection status", gbc);

    gbc.insets.bottom = 5;
    addLabelFieldPair(mainPanel, "Connection Name:", nameField, "A friendly name for this connection", gbc);

    addLabelFieldPair(mainPanel, "User Name:", userField, "Login user name", gbc);

    addLabelFieldPair(mainPanel, "Password:", passwordField, "Login password", gbc);

    JButton showPassword = new LinkButton("Show Password");
    showPassword.setActionCommand("showPassword");
    showPassword.addActionListener(this);

    JPanel passwordOptionsPanel = new JPanel(new GridBagLayout());
    addComponents(passwordOptionsPanel,
            new ComponentToolTipPair[] {
                    new ComponentToolTipPair(savePwdCheck,
                            "Store the password with the connection information"),
                    new ComponentToolTipPair(encryptPwdCheck, "Encrypt the password when saving"),
                    new ComponentToolTipPair(showPassword, "Show the password in plain text") });

    gbc.gridy++;
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    mainPanel.add(passwordOptionsPanel, gbc);

    addLabelFieldPair(mainPanel, "Host Name:", hostField, "Server host name or IP address", gbc);

    addLabelFieldPair(mainPanel, "Port:", portField, "Database port number", gbc);

    addLabelFieldPair(mainPanel, "Data Source:", sourceField, "Data source name", gbc);

    addLabelFieldPair(mainPanel, "JDBC URL:", urlField, "The full JDBC URL for this connection (optional)",
            gbc);

    addDriverFields(mainPanel, gbc);

    connectButton = createButton("Connect", CONNECT_ACTION_COMMAND, 'T');
    disconnectButton = createButton("Disconnect", "disconnect", 'D');

    JPanel buttons = new JPanel(new GridBagLayout());
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.insets.top = 5;
    gbc.insets.left = 0;
    gbc.insets.right = 10;
    gbc.gridwidth = 1;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    gbc.fill = GridBagConstraints.NONE;
    buttons.add(connectButton, gbc);
    gbc.gridx++;
    gbc.weightx = 0;
    buttons.add(disconnectButton, gbc);

    gbc.insets.right = 0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    mainPanel.add(buttons, gbc);

    // ---------------------------------
    // create the advanced panel

    model = new JdbcPropertiesTableModel();
    JTable table = new DefaultTable(model);
    table.getTableHeader().setReorderingAllowed(false);

    TableColumnModel tcm = table.getColumnModel();

    TableColumn column = tcm.getColumn(2);
    column.setCellRenderer(new DeleteButtonRenderer());
    column.setCellEditor(new DeleteButtonEditor(table, new JCheckBox()));
    column.setMaxWidth(24);
    column.setMinWidth(24);

    JScrollPane scroller = new JScrollPane(table);

    // advanced jdbc properties
    JPanel advPropsPanel = new JPanel(new GridBagLayout());
    advPropsPanel.setBorder(BorderFactory.createTitledBorder("JDBC Properties"));
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.insets.right = 10;
    gbc.weighty = 0;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    advPropsPanel.add(new DefaultFieldLabel("Enter any key/value pair properties for this connection"), gbc);
    gbc.gridy++;
    advPropsPanel.add(
            new DefaultFieldLabel("Refer to the relevant JDBC driver documentation for possible entries"), gbc);
    gbc.gridy++;
    gbc.insets.bottom = 10;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    advPropsPanel.add(scroller, gbc);

    // transaction isolation
    txApplyButton = WidgetFactory.createInlineFieldButton("Apply", "transactionLevelChanged");
    txApplyButton.setToolTipText("Apply this level to all open connections of this type");
    txApplyButton.setEnabled(false);
    txApplyButton.addActionListener(this);

    // add a dummy select value to the tx levels
    String[] txLevels = new String[Constants.TRANSACTION_LEVELS.length + 1];
    txLevels[0] = "Database Default";
    for (int i = 1; i < txLevels.length; i++) {
        txLevels[i] = Constants.TRANSACTION_LEVELS[i - 1];
    }
    txCombo = WidgetFactory.createComboBox(txLevels);

    JPanel advTxPanel = new JPanel(new GridBagLayout());
    advTxPanel.setBorder(BorderFactory.createTitledBorder("Transaction Isolation"));
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.insets.right = 10;
    gbc.insets.bottom = 5;
    gbc.weighty = 0;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    advTxPanel.add(new DefaultFieldLabel("Default transaction isolation level for this connection"), gbc);
    gbc.gridy++;
    gbc.insets.bottom = 10;
    advTxPanel.add(
            new DefaultFieldLabel(
                    "Note: the selected isolation level " + "will apply to ALL open connections of this type."),
            gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.weightx = 0;
    advTxPanel.add(new DefaultFieldLabel("Isolation Level:"), gbc);
    gbc.gridx = 1;
    gbc.insets.left = 5;
    gbc.weightx = 1.0;
    gbc.insets.right = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    advTxPanel.add(txCombo, gbc);
    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.insets.left = 0;
    gbc.insets.right = 10;
    advTxPanel.add(txApplyButton, gbc);

    JPanel advancedPanel = new JPanel(new BorderLayout());
    advancedPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    advancedPanel.add(advPropsPanel, BorderLayout.CENTER);
    advancedPanel.add(advTxPanel, BorderLayout.SOUTH);

    JScrollPane scrollPane = new JScrollPane(mainPanel);
    scrollPane.setBorder(null);

    sshTunnelConnectionPanel = new SSHTunnelConnectionPanel();

    tabPane = new JTabbedPane(JTabbedPane.BOTTOM);
    tabPane.addTab("Basic", scrollPane);
    tabPane.addTab("Advanced", advancedPanel);
    tabPane.addTab("SSH Tunnel", sshTunnelConnectionPanel);

    tabPane.addChangeListener(this);

    add(tabPane, BorderLayout.CENTER);

    EventMediator.registerListener(this);
}

From source file:pcgen.gui2.dialog.ChooserDialog.java

private void initComponents() {
    setTitle(chooser.getName());//from   w w w  .  j  a  v  a 2  s.  c  om
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            //detach listeners from the chooser
            treeViewModel.setDelegate(null);
            listModel.setListFacade(null);
            chooser.getRemainingSelections().removeReferenceListener(ChooserDialog.this);
        }

    });
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());

    JSplitPane split = new JSplitPane();
    JPanel leftPane = new JPanel(new BorderLayout());
    if (availTable != null) {
        availTable.setAutoCreateRowSorter(true);
        availTable.setTreeViewModel(treeViewModel);
        availTable.getRowSorter().toggleSortOrder(0);
        availTable.addActionListener(this);
        leftPane.add(new JScrollPane(availTable), BorderLayout.CENTER);
    } else {
        availInput.addActionListener(this);
        Dimension maxDim = new Dimension(Integer.MAX_VALUE, availInput.getPreferredSize().height);
        availInput.setMaximumSize(maxDim);
        JPanel availPanel = new JPanel();
        availPanel.setLayout(new BoxLayout(availPanel, BoxLayout.PAGE_AXIS));
        availPanel.add(Box.createRigidArea(new Dimension(10, 30)));
        availPanel.add(Box.createVerticalGlue());
        availPanel.add(new JLabel(LanguageBundle.getString("in_uichooser_value")));
        availPanel.add(availInput);
        availPanel.add(Box.createVerticalGlue());
        leftPane.add(availPanel, BorderLayout.WEST);
    }

    JPanel buttonPane1 = new JPanel(new FlowLayout());
    JButton addButton = new JButton(chooser.getAddButtonName());
    addButton.setActionCommand("ADD");
    addButton.addActionListener(this);
    buttonPane1.add(addButton);
    buttonPane1.add(new JLabel(Icons.Forward16.getImageIcon()));
    leftPane.add(buttonPane1, BorderLayout.SOUTH);

    split.setLeftComponent(leftPane);

    JPanel rightPane = new JPanel(new BorderLayout());
    JPanel labelPane = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    labelPane.add(new JLabel(chooser.getSelectionCountName()), new GridBagConstraints());
    remainingLabel.setText(chooser.getRemainingSelections().get().toString());
    labelPane.add(remainingLabel, gbc);
    labelPane.add(new JLabel(chooser.getSelectedTableTitle()), gbc);
    rightPane.add(labelPane, BorderLayout.NORTH);

    list.setModel(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addActionListener(this);
    rightPane.add(new JScrollPane(list), BorderLayout.CENTER);

    JPanel buttonPane2 = new JPanel(new FlowLayout());
    buttonPane2.add(new JLabel(Icons.Back16.getImageIcon()));
    JButton removeButton = new JButton(chooser.getRemoveButtonName());
    removeButton.setActionCommand("REMOVE");
    removeButton.addActionListener(this);
    buttonPane2.add(removeButton);
    rightPane.add(buttonPane2, BorderLayout.SOUTH);

    split.setRightComponent(rightPane);

    if (chooser.isInfoAvailable()) {
        JSplitPane infoSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        infoSplit.setTopComponent(split);
        infoSplit.setBottomComponent(infoPane);
        infoSplit.setResizeWeight(0.8);
        pane.add(infoSplit, BorderLayout.CENTER);
        if (availTable != null) {
            availTable.getSelectionModel().addListSelectionListener(this);
        }
    } else {
        pane.add(split, BorderLayout.CENTER);
    }
    JPanel bottomPane = new JPanel(new FlowLayout());
    JButton button = new JButton(LanguageBundle.getString("in_ok")); //$NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_ok")); //$NON-NLS-1$
    button.setActionCommand("OK");
    button.addActionListener(this);
    bottomPane.add(button);
    button = new JButton(LanguageBundle.getString("in_cancel")); //$NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_cancel")); //$NON-NLS-1$
    button.setActionCommand("CANCEL");
    button.addActionListener(this);
    bottomPane.add(button);
    pane.add(bottomPane, BorderLayout.SOUTH);
}

From source file:org.photovault.swingui.PhotoInfoEditor.java

protected void createUI() {
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    tabPane = new JTabbedPane();
    add(tabPane, BorderLayout.CENTER);

    // General pane
    JPanel generalPane = new JPanel();
    tabPane.addTab("General", generalPane);

    // Create the fields & their labels

    // Photographer field
    JLabel photographerLabel = new JLabel("Photographer");
    photographerField = createMvTextField("photographer", 30);
    photographerDoc = photographerField.getDocument();

    // "Fuzzy time" field
    JLabel fuzzyDateLabel = new JLabel("Shooting date");
    fuzzyDateField = new JTextField(30);
    fuzzyDateDoc = fuzzyDateField.getDocument();
    fuzzyDateDoc.putProperty(FIELD, PhotoInfoFields.FUZZY_SHOOT_TIME);
    fuzzyDateDoc.addDocumentListener(this);

    JLabel qualityLabel = new JLabel("Quality");
    qualityField = new JComboBox(qualityStrings);
    qualityField.addActionListener(this);

    StarRating qualityStars = new StarRating(5);
    FieldController<Integer> qfCtrl = ctrl.getFieldController("quality");
    ValueModel qualityFieldValue = new PropertyAdapter(qfCtrl, "value", true);
    ValueModel starCount = new PropertyAdapter(qualityStars, "selection", true);
    PropertyConnector.connect(qualityFieldValue, "value", starCount, "value");

    // Shooting place field
    JLabel shootingPlaceLabel = new JLabel("Shooting place");
    shootingPlaceField = createMvTextField("shotLocation.description", 30);
    shootingPlaceDoc = shootingPlaceField.getDocument();
    JLabel shotLocRoadLabel = new JLabel("Road");
    JTextField shotLocRoadField = createMvTextField("shotLocation.road", 30);
    JLabel shotLocSuburbLabel = new JLabel("Suburb");
    JTextField shotLocSuburbField = createMvTextField("shotLocation.suburb", 30);
    JLabel shotLocCityLabel = new JLabel("City");
    JTextField shotLocCityField = createMvTextField("shotLocation.city", 30);
    JLabel shotLocCountryLabel = new JLabel("Country");
    JTextField shotLocCountryField = createMvTextField("shotLocation.country", 30);
    JLabel shotLocGeohashLabel = new JLabel("Geohash code");
    JTextField shotLocGeohashField = createMvTextField("shotLocation.geoHashString", 30);
    shotLocGeohashField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "fillAddress");
    shotLocGeohashField.getActionMap().put("fillAddress", new FindAddressAction(ctrl));

    // Tags//from w  w  w. j  a va 2 s.co  m
    JLabel tagLabel = new JLabel("Tags");
    tagList = new TagList2(ctrl.getTagController());
    tagList.setBackground(generalPane.getBackground());

    // Description text
    JLabel descLabel = new JLabel("Description");
    descriptionTextArea = new JTextArea(5, 40);
    descriptionTextArea.setLineWrap(true);
    descriptionTextArea.setWrapStyleWord(true);
    JScrollPane descScrollPane = new JScrollPane(descriptionTextArea);
    descScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    Border descBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
    descBorder = BorderFactory.createTitledBorder(descBorder, "Description");
    descScrollPane.setBorder(descBorder);
    descriptionDoc = descriptionTextArea.getDocument();
    descriptionDoc.putProperty(FIELD, PhotoInfoFields.DESCRIPTION);
    descriptionDoc.addDocumentListener(this);

    // Lay out the created controls
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    generalPane.setLayout(layout);
    JLabel[] labels = { photographerLabel, fuzzyDateLabel, shootingPlaceLabel, shotLocGeohashLabel,
            shotLocRoadLabel, shotLocSuburbLabel, shotLocCityLabel, shotLocCountryLabel, qualityLabel,
            tagLabel };
    JComponent[] fields = { photographerField, fuzzyDateField, shootingPlaceField, shotLocGeohashField,
            shotLocRoadField, shotLocSuburbField, shotLocCityField, shotLocCountryField, qualityStars,
            tagList };
    addLabelTextRows(labels, fields, layout, generalPane);
    c = layout.getConstraints(tagList);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0.0;
    c.weighty = 1.0;
    layout.setConstraints(tagList, c);

    generalPane.add(descScrollPane);
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weighty = 0.5;
    c.fill = GridBagConstraints.BOTH;
    layout.setConstraints(descScrollPane, c);

    c = new GridBagConstraints();
    c.gridwidth = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    c.gridy = GridBagConstraints.RELATIVE;

    c.gridy = GridBagConstraints.RELATIVE;

    createTechDataUI();
    createFolderPaneUI();
    createRightsUI();
}

From source file:QuoteServerThread.java

public void init() {
        //Initialize networking stuff.
        String host = getCodeBase().getHost();

        try {/* www.  j av  a 2  s  .  c o m*/
            address = InetAddress.getByName(host);
        } catch (UnknownHostException e) {
            System.out.println("Couldn't get Internet address: Unknown host");
            // What should we do?
        }

        try {
            socket = new DatagramSocket();
        } catch (IOException e) {
            System.out.println("Couldn't create new DatagramSocket");
            return;
        }

        //Set up the UI.
        GridBagLayout gridBag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        setLayout(gridBag);

        Label l1 = new Label("Quote of the Moment:", Label.CENTER);
        c.anchor = GridBagConstraints.SOUTH;
        c.gridwidth = GridBagConstraints.REMAINDER;
        gridBag.setConstraints(l1, c);
        add(l1);

        display = new Label("(no quote received yet)", Label.CENTER);
        c.anchor = GridBagConstraints.NORTH;
        c.weightx = 1.0;
        c.fill = GridBagConstraints.HORIZONTAL;
        gridBag.setConstraints(display, c);
        add(display);

        Label l2 = new Label("Enter the port (on host " + host + ") to send the request to:", Label.RIGHT);
        c.anchor = GridBagConstraints.SOUTH;
        c.gridwidth = 1;
        c.weightx = 0.0;
        c.weighty = 1.0;
        c.fill = GridBagConstraints.NONE;
        gridBag.setConstraints(l2, c);
        add(l2);

        portField = new TextField(6);
        gridBag.setConstraints(portField, c);
        add(portField);

        Button button = new Button("Send");
        gridBag.setConstraints(button, c);
        add(button);

        portField.addActionListener(this);
        button.addActionListener(this);
    }

From source file:captureplugin.drivers.defaultdriver.AdditionalParams.java

/**
 * Create Details-Panel/* w  w  w .  j av  a  2  s. co  m*/
 * @return Details-Panel
 */
private JPanel createDetailsPanel() {
    JPanel panel = new JPanel(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();

    c.weighty = 0.5;
    c.weightx = 1.0;
    c.insets = new Insets(0, 0, 5, 0);
    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;

    GridBagConstraints l = new GridBagConstraints();

    l.weightx = 1.0;
    l.insets = new Insets(0, 0, 5, 0);
    l.fill = GridBagConstraints.HORIZONTAL;
    l.gridwidth = GridBagConstraints.REMAINDER;

    panel.add(new JLabel(mLocalizer.msg("Name", "Name")), l);

    mName = new JTextField();

    panel.add(mName, l);

    panel.add(new JLabel(mLocalizer.msg("Parameter", "Parameter")), l);

    mParam = new ParamInputField(new CaptureParamLibrary(mConfig), "", false);
    panel.add(mParam, c);

    return panel;
}

From source file:org.openconcerto.erp.core.sales.pos.element.SaisieVenteComptoirSQLElement.java

public SQLComponent createComponent() {
    return new BaseSQLComponent(this) {
        private final JCheckBox checkService = new JCheckBox("dont ");
        private SQLSearchableTextCombo textNom;
        private DeviseField textMontantTTC;
        private DeviseField textMontantService;
        private ElementComboBox comboFournisseur;
        private JTextField textEcheance;

        private ElementComboBox comboTaxe;
        private DeviseField textMontantHT;
        private JCheckBox checkCommande;
        private JDate dateSaisie;

        private ElementComboBox nomArticle;
        private Date dateEch;
        private JLabel labelEcheancejours = new JLabel("jours");
        private ElementComboBox comboAvoir;
        private ElementComboBox comboClient;

        private final JLabel labelWarning = new JLabelWarning(
                "le montant du service ne peut pas dpasser le total HT!");
        private ValidState validState = ValidState.getTrueInstance();
        // FIXME: use w
        private Where w;
        private DocumentListener docTTCListen;
        private PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {

                if ((nomArticle.getValidState().isValid()) && (!nomArticle.isEmpty()) && !isFilling()) {
                    int idArticle = nomArticle.getValue().intValue();

                    SQLTable tableArticle = ((ComptaPropsConfiguration) Configuration.getInstance())
                            .getRootSociete().getTable("ARTICLE");
                    SQLRow rowArticle = tableArticle.getRow(idArticle);
                    if (rowArticle != null) {
                        comboTaxe.setValue(rowArticle.getInt("ID_TAXE"));

                        textMontantTTC.setText(((BigDecimal) rowArticle.getObject("PV_TTC")).toString());
                    }//from   w w w  . ja  v a  2 s  .  c o  m
                    System.out.println("value article Changed");

                }
            }
        };

        public void addViews() {
            this.setLayout(new GridBagLayout());
            final GridBagConstraints c = new DefaultGridBagConstraints();

            this.docTTCListen = new DocumentListener() {
                public void changedUpdate(DocumentEvent e) {
                    calculMontant();
                }

                public void removeUpdate(DocumentEvent e) {
                    calculMontant();
                }

                public void insertUpdate(DocumentEvent e) {
                    calculMontant();
                }
            };

            /***********************************************************************************
             * * RENSEIGNEMENTS
             **********************************************************************************/
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.gridheight = 1;
            TitledSeparator sep = new TitledSeparator("Renseignements");
            this.add(sep, c);
            c.insets = new Insets(2, 2, 1, 2);

            c.gridwidth = 1;

            // Libell vente
            JLabel labelNom = new JLabel(getLabelFor("NOM"));
            labelNom.setHorizontalAlignment(SwingConstants.RIGHT);
            c.gridy++;
            c.gridx = 0;
            c.weightx = 0;
            this.add(labelNom, c);

            this.textNom = new SQLSearchableTextCombo();
            c.gridx++;
            c.weightx = 1;
            c.gridwidth = 2;
            this.add(this.textNom, c);

            // Date
            JLabel labelDate = new JLabel(getLabelFor("DATE"));

            this.dateSaisie = new JDate(true);
            c.gridwidth = 1;
            // c.gridx += 2;
            c.gridx = 0;
            c.gridy++;
            c.weightx = 0;
            labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
            this.add(labelDate, c);
            c.gridx++;
            c.weightx = 1;
            this.add(this.dateSaisie, c);

            // article
            c.gridy++;
            c.gridx = 0;

            this.nomArticle = new ElementComboBox();

            JLabel labelNomArticle = new JLabel(getLabelFor("ID_ARTICLE"));
            c.weightx = 0;
            labelNomArticle.setHorizontalAlignment(SwingConstants.RIGHT);
            // this.add(labelNomArticle, c);

            c.gridx++;
            c.weightx = 0;
            c.gridwidth = GridBagConstraints.REMAINDER;
            // this.add(this.nomArticle, c);

            this.nomArticle.addValueListener(this.propertyChangeListener);

            // client
            this.comboClient = new ElementComboBox();
            this.comboClient.addValueListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {

                    if (comboClient.isEmpty()) {
                        w = new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=",
                                -1);
                    } else {
                        w = new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=",
                                comboClient.getSelectedId());
                    }
                }
            });

            JLabel labelNomClient = new JLabel(getLabelFor("ID_CLIENT"));
            c.gridy++;
            c.gridx = 0;
            c.gridwidth = 1;
            c.weightx = 0;
            labelNomClient.setHorizontalAlignment(SwingConstants.RIGHT);
            this.add(labelNomClient, c);

            c.gridx++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.weightx = 0;
            this.add(this.comboClient, c);

            // Selection d'un avoir si le client en possede

            this.comboAvoir = new ElementComboBox();

            JLabel labelAvoirClient = new JLabel(getLabelFor("ID_AVOIR_CLIENT"));
            c.gridy++;
            c.gridx = 0;
            c.gridwidth = 1;
            c.weightx = 0;
            labelAvoirClient.setHorizontalAlignment(SwingConstants.RIGHT);
            // this.add(labelAvoirClient, c);

            c.gridx++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.weightx = 0;
            // this.add(this.comboAvoir, c);

            /***********************************************************************************
             * * MONTANT
             **********************************************************************************/
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.gridx = 0;
            c.gridy++;
            c.weightx = 1;
            sep = new TitledSeparator("Montant en Euros");
            c.insets = new Insets(10, 2, 1, 2);
            this.add(sep, c);
            c.insets = new Insets(2, 2, 1, 2);

            c.gridwidth = 1;

            final JLabel labelMontantHT = new JLabel(getLabelFor("MONTANT_HT"));
            labelMontantHT.setHorizontalAlignment(SwingConstants.RIGHT);
            this.textMontantHT = new DeviseField();
            this.textMontantHT.setEditable(false);
            this.textMontantHT.setEnabled(false);
            this.textMontantHT.setFocusable(false);

            final JLabel labelMontantTTC = new JLabel(getLabelFor("MONTANT_TTC"));
            labelMontantTTC.setHorizontalAlignment(SwingConstants.RIGHT);
            this.textMontantTTC = new DeviseField();
            this.textMontantTTC.getDocument().addDocumentListener(this.docTTCListen);

            // Montant HT
            c.fill = GridBagConstraints.HORIZONTAL;

            c.weightx = 0;
            c.gridy++;
            c.gridx = 0;
            c.gridwidth = 1;
            this.add(labelMontantHT, c);

            c.gridx++;
            c.weightx = 1;
            this.add(this.textMontantHT, c);

            // Montant Service

            c.gridx++;

            c.weightx = 0;
            this.add(checkService, c);

            checkService.addActionListener(new ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                    if (isFilling())
                        return;
                    boolean b = checkService.isSelected();
                    textMontantService.setEditable(b);
                    textMontantService.setEnabled(b);
                    textMontantService.setFocusable(b);

                    if (!b) {
                        textMontantService.setText("");
                        // montantServiceValide = true;
                    } else {
                        textMontantService.setText(textMontantHT.getText());
                    }
                };
            });

            this.textMontantService = new DeviseField();
            c.gridx++;
            c.weightx = 1;
            this.add(this.textMontantService, c);

            JLabel labelMontantService = new JLabel("de service HT");
            c.weightx = 0;
            c.gridx++;
            this.add(labelMontantService, c);

            c.gridx++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            this.add(this.labelWarning, c);
            this.labelWarning.setVisible(false);

            // Choix TVA
            c.gridy++;
            c.gridx = 0;
            c.weightx = 0;
            c.gridwidth = 1;

            final JLabel labelTaxe = new JLabel(getLabelFor("ID_TAXE"));
            labelTaxe.setHorizontalAlignment(SwingUtilities.RIGHT);
            this.add(labelTaxe, c);

            c.gridx++;
            this.comboTaxe = new ElementComboBox(false);

            c.fill = GridBagConstraints.NONE;

            this.add(this.comboTaxe, c);

            c.fill = GridBagConstraints.HORIZONTAL;

            // Montant TTC
            c.gridy++;
            c.gridx = 0;
            c.weightx = 0;
            this.add(labelMontantTTC, c);

            c.gridx++;
            c.weightx = 0;
            this.add(this.textMontantTTC, c);

            /***********************************************************************************
             * * MODE DE REGLEMENT
             **********************************************************************************/
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.gridx = 0;
            c.gridy++;
            sep = new TitledSeparator("Mode de rglement");
            c.insets = new Insets(10, 2, 1, 2);
            this.add(sep, c);
            c.insets = new Insets(2, 2, 1, 2);

            c.gridx = 0;
            c.gridy++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            this.addView("ID_MODE_REGLEMENT", REQ + ";" + DEC + ";" + SEP);
            ElementSQLObject eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT");
            this.add(eltModeRegl, c);

            /***********************************************************************************
             * * COMMANDE
             **********************************************************************************/
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.gridx = 0;
            c.gridy++;
            sep = new TitledSeparator("Commande");
            c.insets = new Insets(10, 2, 1, 2);
            this.add(sep, c);
            c.insets = new Insets(2, 2, 1, 2);

            this.checkCommande = new JCheckBox("Produit  commander");

            c.gridx = 0;
            c.gridy++;
            c.weightx = 0;
            c.gridwidth = 2;
            // this.add(this.checkCommande, c);

            this.checkCommande.addActionListener(new ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                    boolean b = checkCommande.isSelected();
                    comboFournisseur.setEnabled(b);
                    comboFournisseur.setEditable(b);

                    textEcheance.setEditable(b);
                    textEcheance.setEnabled(b);

                    updateValidState();
                };
            });

            // Fournisseurs
            JLabel labelFournisseur = new JLabel(getLabelFor("ID_FOURNISSEUR"));
            c.gridx = 0;
            c.gridy++;
            c.weightx = 0;
            c.gridwidth = 1;
            labelFournisseur.setHorizontalAlignment(SwingConstants.RIGHT);
            // this.add(labelFournisseur, c);

            this.comboFournisseur = new ElementComboBox();

            c.gridx++;
            c.weightx = 1;
            c.gridwidth = 4;
            // this.add(this.comboFournisseur, c);

            // Echeance
            JLabel labelEcheance = new JLabel("Echeance");
            c.gridx = 0;
            c.gridy++;
            c.weightx = 0;
            c.gridwidth = 1;
            labelEcheance.setHorizontalAlignment(SwingConstants.RIGHT);
            // this.add(labelEcheance, c);

            c.gridx++;
            c.weightx = 1;
            this.textEcheance = new JTextField();
            // this.add(this.textEcheance, c);
            this.textEcheance.addKeyListener(new KeyAdapter() {

                public void keyReleased(KeyEvent e) {
                    calculDate();
                }
            });

            c.gridx++;
            c.weightx = 0;
            // this.add(this.labelEcheancejours, c);

            /***********************************************************************************
             * * INFORMATIONS COMPLEMENTAIRES
             **********************************************************************************/
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.gridx = 0;
            c.gridy++;
            sep = new TitledSeparator("Informations complmentaires");
            c.insets = new Insets(10, 2, 1, 2);
            // this.add(sep, c);
            c.insets = new Insets(2, 2, 1, 2);

            ITextArea textInfos = new ITextArea();

            c.gridx = 0;
            c.gridy++;
            c.gridheight = GridBagConstraints.REMAINDER;
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.weightx = 1;
            c.weighty = 1;
            c.fill = GridBagConstraints.BOTH;
            // this.add(textInfos, c);

            this.addSQLObject(this.textNom, "NOM");
            this.addRequiredSQLObject(this.comboClient, "ID_CLIENT");
            this.addSQLObject(this.nomArticle, "ID_ARTICLE");
            this.addRequiredSQLObject(this.textMontantTTC, "MONTANT_TTC");
            this.addRequiredSQLObject(this.textMontantHT, "MONTANT_HT");
            this.addSQLObject(this.textMontantService, "MONTANT_SERVICE");
            this.addRequiredSQLObject(this.dateSaisie, "DATE");
            this.addSQLObject(textInfos, "INFOS");
            this.addSQLObject(this.comboFournisseur, "ID_FOURNISSEUR");
            this.addSQLObject(this.textEcheance, "ECHEANCE");
            this.addRequiredSQLObject(this.comboTaxe, "ID_TAXE");
            this.addSQLObject(this.comboAvoir, "ID_AVOIR_CLIENT");
            this.comboTaxe.setButtonsVisible(false);
            this.comboTaxe.setValue(2);

            checkService.setSelected(false);
            this.textMontantService.setEditable(false);
            this.textMontantService.setEnabled(false);

            this.checkCommande.setSelected(false);
            this.comboFournisseur.setEditable(false);
            this.comboFournisseur.setEnabled(false);
            this.textEcheance.setEditable(false);
            this.textEcheance.setEnabled(false);

            this.comboTaxe.addValueListener(new PropertyChangeListener() {

                public void propertyChange(PropertyChangeEvent evt) {
                    calculMontant();
                }
            });

            final SimpleDocumentListener docL = new SimpleDocumentListener() {
                @Override
                public void update(DocumentEvent e) {
                    updateValidState();
                }
            };
            this.textMontantService.getDocument().addDocumentListener(docL);
            this.textMontantHT.getDocument().addDocumentListener(docL);
            this.comboFournisseur.addEmptyListener(new EmptyListener() {
                @Override
                public void emptyChange(EmptyObj src, boolean newValue) {
                    updateValidState();
                }
            });

            /*
             * this.nomClient.addValueListener(new PropertyChangeListener() {
             * 
             * public void propertyChange(PropertyChangeEvent evt) { if (nomClient.isValid()) {
             * System.err.println("Changed Combo Avoir"); comboAvoir = new ElementComboBox(new
             * AvoirClientSQLElement(new Where(new
             * AvoirClientSQLElement().getTable().getField("ID_CLIENT"), "=",
             * nomClient.getValue()))); if (comboAvoir != null) { comboAvoir.setEnabled(true); }
             * } else { comboAvoir.setEnabled(false); } } });
             */

        }

        @Override
        public Set<String> getPartialResetNames() {
            Set<String> s = new HashSet<String>();
            s.addAll(super.getPartialResetNames());
            s.add("MONTANT_TTC");
            s.add("MONTANT_SERVICE");
            s.add("MONTANT_HT");
            s.add("NOM");
            s.add("ID_AVOIR_CLIENT");
            s.add("ID_ARTICLE");
            s.add("INFOS");
            return s;
        }

        private void calculMontant() {

            if (!isFilling()) {

                float taux;
                // PrixHT pHT;
                PrixTTC pTTC;
                // taux de la TVA selectionnee
                int idTaxe = this.comboTaxe.getSelectedId();
                if (idTaxe > 1) {
                    SQLRow ligneTaxe = getTable().getBase().getTable("TAXE").getRow(idTaxe);
                    if (ligneTaxe != null) {
                        taux = (ligneTaxe.getFloat("TAUX")) / 100.0F;

                        // calcul des montants HT ou TTC
                        if (this.textMontantTTC.getText().trim().length() > 0) {

                            if (this.textMontantTTC.getText().trim().equals("-")) {
                                pTTC = new PrixTTC(0);
                            } else {
                                pTTC = new PrixTTC(
                                        GestionDevise.parseLongCurrency(this.textMontantTTC.getText()));
                            }

                            // affichage
                            updateTextHT(GestionDevise.currencyToString(pTTC.calculLongHT(taux)));
                        } else {
                            updateTextHT("");
                        }
                    }
                }
            }
        }

        private boolean isMontantServiceValid() {
            String montant = this.textMontantService.getText().trim();
            String montantHT = this.textMontantHT.getText().trim();

            boolean b;
            if (montant.length() == 0) {
                b = true;
            } else {
                if (montantHT.length() == 0) {
                    b = false;
                } else {
                    b = (GestionDevise.parseLongCurrency(montantHT) >= GestionDevise
                            .parseLongCurrency(montant));
                }
            }

            this.labelWarning.setVisible(!b);
            System.err.println("Montant service is valid ? " + b + " --> HT val " + montantHT
                    + " --> service val " + montant);

            return b;
        }

        /*
         * private void calculMontantHT() {
         * 
         * float taux; PrixHT pHT;
         * 
         * if (!this.comboTaxe.isEmpty()) { // taux de la TVA selectionnee SQLRow ligneTaxe =
         * Configuration.getInstance().getBase().getTable("TAXE").getRow(((Integer)
         * this.comboTaxe.getValue()).intValue()); taux = (ligneTaxe.getFloat("TAUX")) / 100; //
         * calcul des montants HT ou TTC if (this.textMontantHT.getText().trim().length() > 0) {
         * 
         * if (this.textMontantHT.getText().trim().equals("-")) { pHT = new PrixHT(0); } else {
         * pHT = new PrixHT(Float.parseFloat(this.textMontantHT.getText())); } // affichage
         * updateTextTTC(String.valueOf(pHT.CalculTTC(taux))); } else updateTextTTC(""); } }
         */

        private void updateTextHT(final String prixHT) {
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {

                    textMontantHT.setText(prixHT);
                }
            });
        }

        @Override
        protected SQLRowValues createDefaults() {
            SQLRowValues vals = new SQLRowValues(this.getTable());
            SQLRowAccessor r;

            try {
                r = ModeReglementDefautPrefPanel.getDefaultRow(true);
                SQLElement eltModeReglement = Configuration.getInstance().getDirectory()
                        .getElement("MODE_REGLEMENT");
                if (r.getID() > 1) {
                    SQLRowValues rowVals = eltModeReglement.createCopy(r.getID());
                    System.err.println(rowVals.getInt("ID_TYPE_REGLEMENT"));
                    vals.put("ID_MODE_REGLEMENT", rowVals);
                }
            } catch (SQLException e) {
                System.err.println("Impossible de slectionner le mode de rglement par dfaut du client.");
                e.printStackTrace();
            }
            return vals;
        }

        // private void updateTextTTC(final String prixTTC) {
        // SwingUtilities.invokeLater(new Runnable() {
        //
        // public void run() {
        //
        // if (docTTCListen != null) {
        //
        // textMontantTTC.getDocument().removeDocumentListener(docTTCListen);
        // }
        //
        // textMontantTTC.setText(prixTTC);
        //
        // // textTaxe.setText(prixTVA);
        // textMontantTTC.getDocument().addDocumentListener(docTTCListen);
        // }
        // });
        // }

        private void calculDate() {

            int aJ = 0;

            // on rcupre les valeurs saisies
            if (this.textEcheance.getText().trim().length() != 0) {

                try {
                    aJ = Integer.parseInt(this.textEcheance.getText());
                } catch (Exception e) {
                    System.out.println("Erreur de format sur TextField Ajour " + this.textEcheance.getText());
                }
            }

            Calendar cal = Calendar.getInstance();

            // on fixe le temps sur ToDay + Ajour
            cal.setTime(new Date());
            long tempsMil = aJ * 86400000;
            cal.setTimeInMillis(cal.getTimeInMillis() + tempsMil);

            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
            this.dateEch = cal.getTime();
            this.labelEcheancejours.setText("jours, soit le " + dateFormat.format(this.dateEch));
        }

        private void updateValidState() {
            this.setValidState(this.computeValidState());
        }

        private ValidState computeValidState() {
            ValidState res = ValidState.getTrueInstance();
            if (!this.isMontantServiceValid())
                res = res.and(ValidState.createCached(false, this.labelWarning.getText()));
            if (this.checkCommande.isSelected())
                res = res.and(ValidState.createCached(!this.comboFournisseur.isEmpty(),
                        "Fournisseur non renseign"));
            return res;
        }

        private final void setValidState(ValidState validState) {
            if (!validState.equals(this.validState)) {
                this.validState = validState;
                this.fireValidChange();
            }
        }

        @Override
        public synchronized ValidState getValidState() {
            return super.getValidState().and(this.validState);
        }

        public int insert(SQLRow order) {

            // On teste si l'article n'existe pas, on le cre
            if (this.nomArticle.isEmpty()) {
                createArticle();
            }

            if (this.textNom.getValue() == null || this.textNom.getValue().trim().length() <= 0) {
                this.textNom.setValue(this.nomArticle.getTextComp().getText());
            }
            final int id = super.insert(order);
            // on verifie si le produit est  commander
            if (this.checkCommande.isSelected()) {
                createCommande(id);
            }

            SQLRow rowArt = getTable().getRow(id).getForeignRow("ID_ARTICLE");
            if (rowArt != null && !rowArt.isUndefined() && rowArt.getBoolean("GESTION_STOCK")) {
                Configuration.getInstance().getNonInteractiveSQLExecutor().execute(new Runnable() {

                    @Override
                    public void run() {

                        final SQLRow rowVC = getTable().getRow(id);
                        // Mise  jour des stocks
                        final SQLElement eltMvtStock = Configuration.getInstance().getDirectory()
                                .getElement("MOUVEMENT_STOCK");
                        final SQLRowValues rowVals = new SQLRowValues(eltMvtStock.getTable());
                        rowVals.put("QTE", -1);
                        rowVals.put("NOM", "Saisie vente comptoir");
                        rowVals.put("IDSOURCE", id);
                        rowVals.put("SOURCE", getTable().getName());
                        rowVals.put("ID_ARTICLE", rowVC.getInt("ID_ARTICLE"));
                        rowVals.put("DATE", rowVC.getObject("DATE"));

                        try {
                            final SQLRow row = rowVals.insert();
                            final ListMap<SQLRow, SQLRowValues> map = ((MouvementStockSQLElement) Configuration
                                    .getInstance().getDirectory().getElement("MOUVEMENT_STOCK"))
                                            .updateStock(Arrays.asList(row), false);
                            MouvementStockSQLElement.createCommandeF(map, null);

                        } catch (SQLException e) {
                            ExceptionHandler.handle("Erreur lors de la cration des mouvements de stock", e);
                        }
                    }
                });

            }
            new GenerationMvtSaisieVenteComptoir(id);
            return id;
        }

        private void createCommande(final int id) {

            System.out.println("Ajout d'une commande");
            SQLRow rowSaisie = SaisieVenteComptoirSQLElement.this.getTable().getRow(id);
            Map<String, Object> m = new HashMap<String, Object>();
            // NOM, DATE, ECHEANCE, IDSOURCE, SOURCE, ID_CLI, ID_FOURN, ID_ARTICLE
            m.put("NOM", rowSaisie.getObject("NOM"));
            m.put("DATE", rowSaisie.getObject("DATE"));
            m.put("DATE_ECHEANCE", new java.sql.Date(this.dateEch.getTime()));

            m.put("IDSOURCE", new Integer(id));
            m.put("SOURCE", "SAISIE_VENTE_COMPTOIR");

            m.put("ID_CLIENT", rowSaisie.getObject("ID_CLIENT"));
            m.put("ID_FOURNISSEUR", rowSaisie.getObject("ID_FOURNISSEUR"));
            m.put("ID_ARTICLE", rowSaisie.getObject("ID_ARTICLE"));

            SQLTable tableCmd = getTable().getBase().getTable("COMMANDE_CLIENT");

            SQLRowValues valCmd = new SQLRowValues(tableCmd, m);

            try {
                if (valCmd.getInvalid() == null) {
                    // ajout de l'ecriture
                    valCmd.insert();
                }
            } catch (Exception e) {
                System.err.println("Erreur  l'insertion dans la table " + valCmd.getTable().getName());
                e.printStackTrace();
            }
        }

        private void createArticle() {
            System.out.println("Cration de l'article");

            String tNomArticle = this.nomArticle.getTextComp().getText();
            String codeArticle = "";// this.nomArticle.getTextOpt();

            if (tNomArticle.trim().length() == 0 && codeArticle.trim().length() == 0) {
                return;
            }

            SQLTable articleTable = getTable().getBase().getTable("ARTICLE");

            int idTaxe = this.comboTaxe.getSelectedId();
            final BigDecimal prix = StringUtils.getBigDecimalFromUserText(this.textMontantHT.getText());
            final BigDecimal prixTTC = StringUtils.getBigDecimalFromUserText(this.textMontantTTC.getText());

            if (tNomArticle.trim().length() == 0) {
                tNomArticle = "Nom Indefini";
            }
            if (codeArticle.trim().length() == 0) {
                codeArticle = "Indefini";
            }

            SQLRowValues vals = new SQLRowValues(articleTable);
            vals.put("NOM", tNomArticle);
            vals.put("CODE", codeArticle);
            vals.put("PA_HT", prix);
            vals.put("PV_HT", prix);
            vals.put("PRIX_METRIQUE_VT_1", prix);
            vals.put("PRIX_METRIQUE_HA_1", prix);
            vals.put("PV_TTC", prixTTC);
            vals.put("ID_UNITE_VENTE", UniteVenteArticleSQLElement.A_LA_PIECE);
            vals.put("ID_TAXE", new Integer(idTaxe));
            vals.put("CREATION_AUTO", Boolean.TRUE);
            vals.put("GESTION_STOCK", Boolean.FALSE);

            try {
                SQLRow row = vals.insert();
                this.nomArticle.setValue(row);
            } catch (SQLException e) {

                e.printStackTrace();
            }
        }

        public void update() {

            if (JOptionPane.showConfirmDialog(this,
                    "Attention en modifiant cette vente comptoir, vous supprimerez les chques et les chances associs. Continuer?",
                    "Modification de vente comptoir", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                // on efface les mouvements de stocks associs
                SQLRow row = getTable().getRow(this.getSelectedID());
                SQLElement eltMvtStock = Configuration.getInstance().getDirectory()
                        .getElement("MOUVEMENT_STOCK");
                SQLSelect sel = new SQLSelect();
                sel.addSelect(eltMvtStock.getTable().getField("ID"));
                Where w = new Where(eltMvtStock.getTable().getField("IDSOURCE"), "=", row.getID());
                Where w2 = new Where(eltMvtStock.getTable().getField("SOURCE"), "=", getTable().getName());
                sel.setWhere(w.and(w2));

                List l = (List) eltMvtStock.getTable().getBase().getDataSource().execute(sel.asString(),
                        new ArrayListHandler());
                if (l != null) {
                    for (int i = 0; i < l.size(); i++) {
                        Object[] tmp = (Object[]) l.get(i);
                        try {
                            eltMvtStock.archive(((Number) tmp[0]).intValue());
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                }

                if (this.textNom.getValue() != null && this.textNom.getValue().trim().length() <= 0) {
                    this.textNom.setValue(this.nomArticle.getTextComp().getText());
                }

                // On teste si l'article n'existe pas, on le cre
                if (this.nomArticle.getValue() == null
                        || Integer.parseInt(this.nomArticle.getValue().toString()) == -1) {
                    createArticle();
                }

                // TODO check echeance, ---> creation article, commande??
                super.update();

                row = getTable().getRow(this.getSelectedID());
                int idMvt = row.getInt("ID_MOUVEMENT");
                System.out.println(row.getID() + "__________***************** UPDATE " + idMvt);

                // on supprime tout ce qui est li  la facture
                EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory()
                        .getElement("ECRITURE");
                eltEcr.archiveMouvementProfondeur(idMvt, false);

                SQLRow rowArt = row.getForeignRow("ID_ARTICLE");
                if (rowArt != null && !rowArt.isUndefined() && rowArt.getBoolean("GESTION_STOCK")) {
                    // Mise  jour des stocks
                    SQLRowValues rowVals = new SQLRowValues(eltMvtStock.getTable());
                    rowVals.put("QTE", -1);
                    rowVals.put("NOM", "Saisie vente comptoir");
                    rowVals.put("IDSOURCE", getSelectedID());
                    rowVals.put("SOURCE", getTable().getName());
                    rowVals.put("ID_ARTICLE", row.getInt("ID_ARTICLE"));
                    rowVals.put("DATE", row.getObject("DATE"));
                    try {
                        SQLRow rowNew = rowVals.insert();
                        final ListMap<SQLRow, SQLRowValues> map = ((MouvementStockSQLElement) Configuration
                                .getInstance().getDirectory().getElement("MOUVEMENT_STOCK"))
                                        .updateStock(Arrays.asList(rowNew), false);
                        ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor()
                                .execute(new Runnable() {

                                    @Override
                                    public void run() {
                                        MouvementStockSQLElement.createCommandeF(map, null);
                                    }
                                });
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
                if (idMvt > 1) {
                    new GenerationMvtSaisieVenteComptoir(this.getSelectedID(), idMvt);
                } else {
                    new GenerationMvtSaisieVenteComptoir(this.getSelectedID());
                }
            }
        }

        @Override
        public void select(SQLRowAccessor r) {
            this.textMontantTTC.getDocument().removeDocumentListener(this.docTTCListen);
            this.nomArticle.rmValueListener(this.propertyChangeListener);

            super.select(r);

            checkService.setSelected(
                    r != null && r.getObject("MONTANT_SERVICE") != null && r.getLong("MONTANT_SERVICE") > 0);

            this.textMontantTTC.getDocument().addDocumentListener(this.docTTCListen);
            this.nomArticle.addValueListener(this.propertyChangeListener);
        }

        @Override
        public void select(SQLRowAccessor r, Set<String> views) {
            super.select(r, views);
            checkService.setSelected(
                    r != null && r.getObject("MONTANT_SERVICE") != null && r.getLong("MONTANT_SERVICE") > 0);
        }

    };
}

From source file:org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement.java

public SQLComponent createComponent() {
    return new BaseSQLComponent(this) {

        private Icon iconWarning = ImageIconWarning.getInstance();

        public void addViews() {
            this.setLayout(new GridBagLayout());
            final GridBagConstraints c = new DefaultGridBagConstraints();

            Set<Class<? extends SQLElement>> s = map.keySet();

            final ArrayList<Class<? extends SQLElement>> list = new ArrayList<Class<? extends SQLElement>>(s);
            Collections.sort(list, new Comparator<Class<? extends SQLElement>>() {
                public int compare(Class<? extends SQLElement> o1, Class<? extends SQLElement> o2) {
                    return o1.getSimpleName().toString().compareTo(o2.getSimpleName().toString());
                };/*from   ww  w  .  j  av a  2 s  .c  om*/
            });

            List<String> added = new ArrayList<String>();
            for (Class<? extends SQLElement> class1 : list) {
                String prefix = map.get(class1);
                if (!added.contains(prefix)) {
                    c.gridy++;
                    c.gridx = 0;
                    c.weightx = 0;
                    added.add(prefix);
                    SQLElement elt = Configuration.getInstance().getDirectory().getElement(class1);
                    if (elt == null) {
                        throw new IllegalArgumentException("Element null for class " + class1);
                    }
                    // Avoir
                    JLabel labelAvoirFormat = new JLabel(
                            StringUtils.firstUp(elt.getPluralName()) + " " + getLabelFor(prefix + FORMAT),
                            SwingConstants.RIGHT);
                    this.add(labelAvoirFormat, c);
                    c.gridx++;
                    c.weightx = 1;
                    final JTextField fieldFormat = new JTextField();
                    this.add(fieldFormat, c);

                    final JLabel labelAvoirStart = new JLabel(getLabelFor(prefix + START));
                    c.gridx++;
                    c.weightx = 0;
                    this.add(labelAvoirStart, c);
                    c.gridx++;
                    c.weightx = 1;
                    final JTextField fieldStart = new JTextField();
                    this.add(fieldStart, c);

                    final JLabel labelResult = new JLabel();
                    c.gridx++;
                    c.weightx = 0;
                    this.add(labelResult, c);

                    if (getTable().getFieldsName().contains(prefix + AUTO_MONTH)) {
                        final JCheckBox boxAuto = new JCheckBox(getLabelFor(prefix + AUTO_MONTH));
                        c.gridx++;
                        c.weightx = 0;
                        this.add(boxAuto, c);
                        this.addSQLObject(boxAuto, prefix + AUTO_MONTH);
                    }
                    // Affichage dynamique du rsultat
                    SimpleDocumentListener listener = new SimpleDocumentListener() {

                        @Override
                        public void update(DocumentEvent e) {
                            updateLabel(fieldStart, fieldFormat, labelResult);

                        }
                    };

                    fieldFormat.getDocument().addDocumentListener(listener);
                    fieldStart.getDocument().addDocumentListener(listener);

                    this.addRequiredSQLObject(fieldFormat, prefix + FORMAT);
                    this.addRequiredSQLObject(fieldStart, prefix + START);
                }
            }

            // JLabel labelCodeLettrage = new JLabel(getLabelFor("CODE_LETTRAGE"));
            // c.gridy++;
            // c.gridx = 0;
            // c.weightx = 0;
            // this.add(labelCodeLettrage, c);
            // c.gridx++;
            // c.weightx = 1;
            // this.add(this.textCodeLettrage, c);
            //
            // c.gridx++;
            // c.weightx = 0;
            // labelNextCodeLettrage = new JLabel();
            // this.add(labelNextCodeLettrage, c);

            JLabel labelExemple = new JLabel("Exemple de format : 'Fact'yyyy0000");
            c.gridy++;
            c.gridx = 0;
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.weighty = 1;
            c.anchor = GridBagConstraints.NORTHWEST;
            this.add(labelExemple, c);

            // this.textCodeLettrage.getDocument().addDocumentListener(this.listenText);

        }

        // private void updateLabelNextCode() {
        // String s = getNextCodeLetrrage(this.textCodeLettrage.getText());
        // this.labelNextCodeLettrage.setText(donne + " " + s);
        // }

        private void updateLabel(JTextField textStart, JTextField textFormat, JLabel label) {
            if (textStart.getText().trim().length() > 0) {
                try {
                    String numProposition = getNextNumero(textFormat.getText(),
                            Integer.parseInt(textStart.getText()), new Date());

                    if (numProposition != null) {
                        label.setText(" --> " + numProposition);
                        label.setIcon(null);
                    } else {
                        label.setIcon(this.iconWarning);
                        label.setText("");
                    }
                } catch (IllegalArgumentException e) {
                    JOptionPane.showMessageDialog(null,
                            "Le format " + textFormat.getText() + " n'est pas valide!");
                }
            } else {
                label.setIcon(this.iconWarning);
                label.setText("");
            }
        }

    };
}

From source file:com.intel.stl.ui.monitor.view.PSPortsDetailsPanel.java

protected JPanel createFlowTypePanel() {
    JPanel panel = new JPanel();
    panel.setOpaque(false);//from w  w w  .j  av a  2  s . co  m
    panel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
    GridBagLayout gridBag = new GridBagLayout();
    panel.setLayout(gridBag);
    GridBagConstraints gc = new GridBagConstraints();

    gc.insets = new Insets(8, 2, 2, 2);
    gc.weighty = 0;
    gc.weightx = 1;
    gc.gridwidth = GridBagConstraints.REMAINDER;
    gc.gridheight = 1;
    flowTypeChartPanel = new ChartPanel(null);
    flowTypeChartPanel.setPreferredSize(new Dimension(80, 60));
    panel.add(flowTypeChartPanel, gc);

    flowNumberLabels = new JLabel[flowTypes.length];
    flowNameLabels = new JLabel[flowTypes.length];
    gc.fill = GridBagConstraints.BOTH;
    gc.insets = new Insets(2, 2, 2, 2);
    for (int i = 0; i < flowTypes.length; i++) {
        gc.weightx = 1;
        gc.gridwidth = 1;
        flowNumberLabels[i] = createNumberLabel();
        panel.add(flowNumberLabels[i], gc);

        gc.weightx = 0;
        gc.gridwidth = GridBagConstraints.REMAINDER;
        flowNameLabels[i] = createNameLabel(flowTypes[i].getName());
        panel.add(flowNameLabels[i], gc);
    }

    return panel;
}

From source file:course_generator.param.frmEditCurve.java

/**
 * This method is called to initialize the form.
 *//*ww w.j a v  a2  s  .  com*/
private void initComponents() {
    int line = 0;

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(bundle.getString("frmEditCurve.title"));
    setPreferredSize(new Dimension(1200, 600));
    setAlwaysOnTop(true);
    setResizable(false);
    setType(java.awt.Window.Type.UTILITY);
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });

    // -- Layout
    // ------------------------------------------------------------
    Container paneGlobal = getContentPane();
    paneGlobal.setLayout(new GridBagLayout());

    //-- Curves list
    ListCurves = new javax.swing.JList<>();
    model = new ParamListModel();
    ListCurves.setModel(model);
    ListCurves.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    ListCurves.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            SelectCurve();
        }
    });
    jScrollPaneCurves = new javax.swing.JScrollPane();
    jScrollPaneCurves.setViewportView(ListCurves);

    Utils.addComponent(paneGlobal, jScrollPaneCurves, 0, 0, 1, 4, 0.5, 1, 10, 10, 0, 0,
            GridBagConstraints.PAGE_START, GridBagConstraints.BOTH);

    //-- Curve management toolbar
    CreateCurvesToolbar();
    Utils.addComponent(paneGlobal, ToolBarAction, 1, 0, 1, 4, 0, 0, 10, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    lbSelectedCurve = new javax.swing.JLabel();
    lbSelectedCurve.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbSelectedCurve.setText("Selected");
    lbSelectedCurve.setHorizontalAlignment(JLabel.LEFT);
    Utils.addComponent(paneGlobal, lbSelectedCurve, 2, 0, GridBagConstraints.REMAINDER, 1, 1, 0, 10, 0, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);

    //-- Curve name
    lbName = new javax.swing.JLabel();
    lbName.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbName.setText(" " + bundle.getString("frmEditCurve.lbName.text") + " ");
    Utils.addComponent(paneGlobal, lbName, 2, 1, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING,
            GridBagConstraints.HORIZONTAL);

    lbNameVal = new javax.swing.JLabel();
    lbNameVal.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(paneGlobal, lbNameVal, 3, 1, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    //-- Curve comment
    lbComment = new javax.swing.JLabel();
    lbComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    lbComment.setText(" " + bundle.getString("frmEditCurve.lbComment.text") + " ");
    Utils.addComponent(paneGlobal, lbComment, 2, 2, 1, 1, 0, 0, 0, 0, 5, 0, GridBagConstraints.BASELINE_LEADING,
            GridBagConstraints.HORIZONTAL);

    tfComment = new JTextField();
    tfComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(paneGlobal, tfComment, 3, 2, GridBagConstraints.REMAINDER, 1, 1, 0, 0, 5, 5, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL);

    //-- Point list
    TablePoints = new javax.swing.JTable();
    TablePoints.setModel(tablemodel);//new ParamPointsModel(param));
    TablePoints.getTableHeader().setReorderingAllowed(false);
    TablePoints.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            //            TableMainMouseClicked(evt);
        }
    });
    TablePoints.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            //            TableMainKeyReleased(evt);
        }
    });

    jScrollPanePoint = new javax.swing.JScrollPane();
    jScrollPanePoint.setViewportView(TablePoints);
    Utils.addComponent(paneGlobal, jScrollPanePoint, 2, 3, 2, 1, 0.5, 0, 0, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    //-- Edit toolbar
    CreateEditToolbar();
    Utils.addComponent(paneGlobal, ToolBarEdit, 4, 3, 1, 1, 0, 0, 0, 0, 0, 0,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);

    jPanelProfilChart = new ChartPanel(chart);
    Utils.addComponent(paneGlobal, jPanelProfilChart, 5, 3, 1, 1, 1, 0, 0, 0, 0, 10,
            GridBagConstraints.BASELINE_LEADING, GridBagConstraints.BOTH);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);

    yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
    yCrosshair.setLabelVisible(true);
    yCrosshair.setLabelBackgroundPaint(Color.WHITE);

    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);

    jPanelProfilChart.addOverlay(crosshairOverlay);
    jPanelProfilChart.setBackground(new java.awt.Color(255, 0, 51));
    jPanelProfilChart.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent event) {

            ChartEntity chartentity = event.getEntity();
            if (chartentity instanceof XYItemEntity) {
                XYItemEntity e = (XYItemEntity) chartentity;
                XYDataset d = e.getDataset();
                int s = e.getSeriesIndex();
                int i = e.getItem();
                double x = d.getXValue(s, i);
                double y = d.getYValue(s, i);
                xCrosshair.setValue(x);
                yCrosshair.setValue(y);
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });

    // == Bottom button
    // ===========================================================
    btOk = new javax.swing.JButton();
    btOk.setText(bundle.getString("frmEditCurve.btOk.text"));
    btOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/valid.png")));
    btOk.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            RequestToClose();
        }
    });
    Utils.addComponent(paneGlobal, btOk, 0, 5, GridBagConstraints.REMAINDER, 1, 0, 0, 10, 0, 10, 0,
            GridBagConstraints.CENTER, GridBagConstraints.NONE);

    // --
    pack();

    //-- Refresh the curve list
    RefreshCurveList();

    //-- Center the windows
    setLocationRelativeTo(null);
}