com.archivas.clienttools.arcmover.gui.panels.CopyOptionsPanel.java Source code

Java tutorial

Introduction

Here is the source code for com.archivas.clienttools.arcmover.gui.panels.CopyOptionsPanel.java

Source

// Copyright 2007 Hitachi Data Systems
// All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package com.archivas.clienttools.arcmover.gui.panels;

import com.archivas.clienttools.arcmover.gui.JobDialog;
import com.archivas.clienttools.arcutils.api.jobs.CopyJob;
import org.apache.http.HttpStatus;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class CopyOptionsPanel extends JPanel {

    private JCheckBox ignoreConflictsCheckbox = new JCheckBox(
            "Treat conflict (" + HttpStatus.SC_CONFLICT + ") errors as success");

    private JobDialog jobDialog;

    public CopyOptionsPanel(JobDialog jobDialog, CopyJob copyJob) {
        this.jobDialog = jobDialog;

        layoutGuiComponents();

        initState(copyJob.ignoreConflicts());

        ActionListener l = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                fieldChanged();
            }
        };
        ignoreConflictsCheckbox.addActionListener(l);
    }

    private void layoutGuiComponents() {

        //
        // top level panel
        //
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
        setBorder(new EmptyBorder(24, 24, 24, 24));
        add(ignoreConflictsCheckbox);
        add(Box.createVerticalGlue());

    }

    private void fieldChanged() {
        if (jobDialog != null) {
            jobDialog.fieldChanged();
        }
    }

    public void enablePanel(boolean enabled) {
        ignoreConflictsCheckbox.setEnabled(enabled);
    }

    private void initState(boolean ignoreConflicts) {
        ignoreConflictsCheckbox.setSelected(ignoreConflicts);
    }

    public boolean getIgnoreConflicts() {
        return ignoreConflictsCheckbox.isSelected();
    }

    public static void main(String[] args) {
        // just test this panel.
        CopyOptionsPanel p = new CopyOptionsPanel(null, new CopyJob());
        JFrame f = new JFrame();
        f.add(p);
        f.pack();
        f.setLocation(100, 800);
        f.setSize(new Dimension(700, 500));
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        f.setVisible(true);
    }
}