Skip to content

Commit

Permalink
Wizard: Added CutCopyPaste context menu to all textfields
Browse files Browse the repository at this point in the history
  • Loading branch information
EHJ-52n committed Nov 19, 2018
1 parent 8299e3c commit 31154a9
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 5 deletions.
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2011-2018 52°North Initiative for Geospatial Open Source
* Software GmbH
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* If the program is linked with libraries which are licensed under one of
* the following licenses, the combination of the program with the linked
* library is not considered a "derivative work" of the program:
*
* - Apache License, version 2.0
* - Apache Software License, version 1.0
* - GNU Lesser General Public License, version 3
* - Mozilla Public License, versions 1.0, 1.1 and 2.0
* - Common Development and Distribution License (CDDL), version 1.0
*
* Therefore the distribution of the program linked with libraries licensed
* under the aforementioned licenses, is permitted by the copyright holders
* if the distribution is compliant with both the GNU General Public
* License version 2 and the aforementioned licenses.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*/
package org.n52.sos.importer.view;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.text.DefaultEditorKit;

import org.n52.sos.importer.view.i18n.Lang;

/**
* Provides a cut, copy, and paste {@link JPopupMenu}.
*
* See <a href="https://docs.oracle.com/javase/tutorial/uiswing/dnd/textpaste.html">Oracle Swing Tutorial</a>.
*
* @author <a href="mailto:e.h.juerrens@52north.org">J&uuml;rrens, Eike Hinderk</a>
*
*/
public class CutCopyPasteContextMenu extends JPopupMenu {

private static final long serialVersionUID = 1L;

public CutCopyPasteContextMenu() {
//
// CUT
//
JMenuItem jMenuItem = new JMenuItem(new DefaultEditorKit.CutAction());
jMenuItem.setText(Lang.l().cut());
add(jMenuItem);
//
// COPY
//
jMenuItem = new JMenuItem(new DefaultEditorKit.CopyAction());
jMenuItem.setText(Lang.l().copy());
add(jMenuItem);
//
// PASTE
//
jMenuItem = new JMenuItem(new DefaultEditorKit.PasteAction());
jMenuItem.setText(Lang.l().paste());
add(jMenuItem);
}

}
12 changes: 8 additions & 4 deletions wizard/src/main/java/org/n52/sos/importer/view/Step1Panel.java
Expand Up @@ -104,7 +104,7 @@ public class Step1Panel extends JPanel {
private final JTextField jtfFilenameSchema = new JTextField();
private final JPasswordField jpfPassword = new JPasswordField();
private final JCheckBox jcbRegex = new JCheckBox();
private final JComboBox<String> jcbChooseInputType = new JComboBox<String>(feedingTypes);
private final JComboBox<String> jcbChooseInputType = new JComboBox<>(feedingTypes);
private final Step1Panel _this = this;
private final JPanel cardPanel = new JPanel(new CardLayout());

Expand Down Expand Up @@ -150,7 +150,7 @@ public void actionPerformed(final ActionEvent e) {
final JLabel encodingLabel = new JLabel(Lang.l().step1EncodingLabel() + ":");
encodingLabel.setFont(Constants.DEFAULT_INSTRUCTIONS_FONT_LARGE_BOLD);
final Set<String> charsets = getCharsets();
encodingCB = new JComboBox<String>(charsets.toArray(new String[charsets.size()]));
encodingCB = new JComboBox<>(charsets.toArray(new String[charsets.size()]));
encodingCB.setSelectedIndex(getIndexOfEncoding(Constants.DEFAULT_FILE_ENCODING));

final GridBagConstraints gbcOneTimeFeed = new GridBagConstraints(0, 0, 1, 1, 0, 0,
Expand Down Expand Up @@ -183,10 +183,14 @@ GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2,

// this keylistener instantly checks whether the input data is sufficient
jtfUrl.addKeyListener(keyListener);
jtfUrl.setComponentPopupMenu(new CutCopyPasteContextMenu());
jtfUser.addKeyListener(keyListener);
jtfUser.setComponentPopupMenu(new CutCopyPasteContextMenu());
jpfPassword.addKeyListener(keyListener);
jtfDirectory.addKeyListener(keyListener);
jtfDirectory.setComponentPopupMenu(new CutCopyPasteContextMenu());
jtfFilenameSchema.addKeyListener(keyListener);
jtfFilenameSchema.setComponentPopupMenu(new CutCopyPasteContextMenu());

final GridBagConstraints gbcLabel = new GridBagConstraints(0, 0, 2, 1, 0, 0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2,
Expand Down Expand Up @@ -284,7 +288,7 @@ private int getIndexOfEncoding(final String givenEncodingName) {
* @return a int.
*/
public int getFeedingType() {
return (jcbChooseInputType.getSelectedIndex() == CSV_FILE) ? CSV_FILE : FTP_FILE;
return jcbChooseInputType.getSelectedIndex() == CSV_FILE ? CSV_FILE : FTP_FILE;
}

/**
Expand Down Expand Up @@ -473,7 +477,7 @@ public String getFileEncoding() {
private JPanel initLanguagePanel() {
final JPanel panel = new JPanel();
final JLabel label = new JLabel(Lang.l().step1SelectLanguage());
final JComboBox<Locale> jcb = new JComboBox<Locale>(Lang.getAvailableLocales());
final JComboBox<Locale> jcb = new JComboBox<>(Lang.getAvailableLocales());
jcb.setSelectedItem(Lang.getCurrentLocale());
jcb.setEditable(false);
//
Expand Down
Expand Up @@ -483,6 +483,7 @@ public void actionPerformed(final ActionEvent e) {
offeringInputTextField = new JTextField();
offeringInputTextField.setColumns(10);
offeringInputTextField.setVisible(false);
offeringInputTextField.setComponentPopupMenu(new CutCopyPasteContextMenu());

offeringPanel = new JPanel();
offeringPanel.setBorder(new TitledBorder(null,
Expand Down
15 changes: 15 additions & 0 deletions wizard/src/main/java/org/n52/sos/importer/view/i18n/De.java
Expand Up @@ -1200,4 +1200,19 @@ public String year() {
return "Jahr";
}

@Override
public String cut() {
return "ausschneiden";
}

@Override
public String copy() {
return "kopieren";
}

@Override
public String paste() {
return "einfügen";
}

}
15 changes: 15 additions & 0 deletions wizard/src/main/java/org/n52/sos/importer/view/i18n/En.java
Expand Up @@ -1193,4 +1193,19 @@ public String year() {
return "Year";
}

@Override
public String cut() {
return "cut";
}

@Override
public String copy() {
return "copy";
}

@Override
public String paste() {
return "paste";
}

}
23 changes: 22 additions & 1 deletion wizard/src/main/java/org/n52/sos/importer/view/i18n/Lang.java
Expand Up @@ -1687,7 +1687,7 @@ public abstract String step7SOSConnectionFailedException(String strURL,
*/
public abstract String url();

/**
/**~/
* <p>version.</p>
*
* @return Version
Expand Down Expand Up @@ -1715,4 +1715,25 @@ public abstract String step7SOSConnectionFailedException(String strURL,
*/
public abstract String year();

/**
* <p>cut.</p>
*
* @return cut
*/
public abstract String cut();

/**
* <p>copy.</p>
*
* @return copy
*/
public abstract String copy();

/**
* <p>paste.</p>
*
* @return paste
*/
public abstract String paste();

}
Expand Up @@ -39,6 +39,7 @@
import org.n52.sos.importer.model.position.Position;
import org.n52.sos.importer.model.position.Position.Id;
import org.n52.sos.importer.model.position.PositionComponent;
import org.n52.sos.importer.view.CutCopyPasteContextMenu;
import org.n52.sos.importer.view.MissingComponentPanel;
import org.n52.sos.importer.view.combobox.ComboBoxItems;
import org.n52.sos.importer.view.i18n.Lang;
Expand Down Expand Up @@ -76,6 +77,7 @@ public MissingPositionComponentPanel(Id id, Position position) {
this.position = position;
this.id = id;
textField.setText("0");
textField.setComponentPopupMenu(new CutCopyPasteContextMenu());

setLayout(new FlowLayout(FlowLayout.LEFT));
final String labelSpacer = " ";
Expand Down
Expand Up @@ -66,6 +66,7 @@
import org.n52.sos.importer.model.resources.UnitOfMeasurement;
import org.n52.sos.importer.model.table.Column;
import org.n52.sos.importer.model.table.TableElement;
import org.n52.sos.importer.view.CutCopyPasteContextMenu;
import org.n52.sos.importer.view.MissingComponentPanel;
import org.n52.sos.importer.view.combobox.EditableJComboBoxPanel;
import org.n52.sos.importer.view.i18n.Lang;
Expand Down Expand Up @@ -282,6 +283,7 @@ private JPanel initGeneratedResURIPanel() {

uriOrPrefixTextField = new JTextField();
uriOrPrefixTextField.setColumns(10);
uriOrPrefixTextField.setComponentPopupMenu(new CutCopyPasteContextMenu());
final GridBagConstraints gbc_uriOrPrefixTextField = new GridBagConstraints();
gbc_uriOrPrefixTextField.insets = new Insets(0, 0, 5, 0);
gbc_uriOrPrefixTextField.anchor = GridBagConstraints.NORTH;
Expand Down Expand Up @@ -357,6 +359,7 @@ private JPanel initGeneratedNamePanel(final String[] columnHeadingsWithId) {

columnConcationationString = new JTextField();
columnConcationationString.setColumns(10);
columnConcationationString.setComponentPopupMenu(new CutCopyPasteContextMenu());
final GridBagConstraints gbc_columnConcationationString = new GridBagConstraints();
gbc_columnConcationationString.anchor = GridBagConstraints.NORTH;
gbc_columnConcationationString.fill = GridBagConstraints.HORIZONTAL;
Expand Down

0 comments on commit 31154a9

Please sign in to comment.