001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.tool.service.swing.ui;
021:
022: import javax.swing.JFileChooser;
023: import javax.swing.JFrame;
024: import javax.swing.JOptionPane;
025: import javax.swing.JPanel;
026: import javax.swing.JTextArea;
027: import javax.swing.filechooser.FileFilter;
028: import java.awt.LayoutManager;
029: import java.io.File;
030:
031: public abstract class WizardPane extends JPanel {
032: protected JTextArea descriptionLabel;
033: protected JFrame ownerFrame;
034:
035: protected int descWidth = 400;
036: protected int descHeight = 100;
037: protected int width = 400;
038: protected int height = 300;
039: protected int hgap = 5;
040: protected int vgap = 5;
041:
042: protected WizardPane() {
043: }
044:
045: protected WizardPane(JFrame ownerFrame) {
046: this .ownerFrame = ownerFrame;
047: }
048:
049: protected WizardPane(boolean isDoubleBuffered) {
050: super (isDoubleBuffered);
051: }
052:
053: protected WizardPane(LayoutManager layout) {
054: super (layout);
055: }
056:
057: protected WizardPane(LayoutManager layout, boolean isDoubleBuffered) {
058: super (layout, isDoubleBuffered);
059: }
060:
061: protected void initDescription(String desc) {
062: this .descriptionLabel = new JTextArea(desc);
063: this .descriptionLabel.setOpaque(false);
064: this .descriptionLabel.setEditable(false);
065: this .descriptionLabel.setAutoscrolls(true);
066: this .descriptionLabel.setBounds(0, 0, descWidth, descHeight);
067: this .add(this .descriptionLabel);
068: }
069:
070: public abstract boolean validateValues();
071:
072: protected void showErrorMessage(String message) {
073: JOptionPane.showMessageDialog(this , message, "Error",
074: JOptionPane.ERROR_MESSAGE);
075: }
076:
077: protected String browseForAFile(final String extension) {
078: String str = "";
079: JFileChooser fc = new JFileChooser();
080: fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
081: fc.addChoosableFileFilter(new FileFilter() {
082: public boolean accept(File f) {
083: if (f.getName().endsWith(extension) || f.isDirectory())
084: return true;
085: else
086: return false;
087: }
088:
089: public String getDescription() {
090: return extension + " file filter ";
091: }
092: });
093:
094: int returnVal = fc.showOpenDialog(this );
095: if (returnVal == JFileChooser.APPROVE_OPTION) {
096: str = fc.getSelectedFile().getAbsolutePath().trim();
097: }
098: return str;
099: }
100:
101: protected String browseForAFolder() {
102: String str = "";
103: JFileChooser fc = new JFileChooser();
104: fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
105: int returnVal = fc.showOpenDialog(this);
106: if (returnVal == JFileChooser.APPROVE_OPTION) {
107: str = fc.getSelectedFile().getAbsolutePath().trim();
108: }
109: return str;
110: }
111: }
|