
com.inet.jortho.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yaoqiang-bpmn-editor Show documentation
Show all versions of yaoqiang-bpmn-editor Show documentation
an Open Source BPMN 2.0 Modeler
The newest version!
/*
* JOrtho
*
* Copyright (C) 2005-2008 by i-net software
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Created on 10.11.2005
*/
package com.inet.jortho;
import java.awt.Dialog;
import java.awt.Image;
import java.util.*;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextField;
/**
* @author Volker Berlin
*/
public class Utils {
/**
* Translate a GUI string in one of the supported languages. If the value was not find then the key is returned.
*
* @param value
* the key of the language resource.
* @return the translation result
*/
static String getResource( String value ) {
try {
ResourceBundle resource = ResourceBundle.getBundle( "com.inet.jortho.i18n.resource" );
return resource.getString( value );
} catch( Exception e ) {
if( !value.endsWith( ".tooltip" ) ) { // Tooltip is something extra. Ignore it if not there
SpellChecker.getMessageHandler().handleException( e );
}
}
return value;
}
/**
* Creates a JButton with a text, tooltip and a key modifier as needed
* @param resource the key of the language resource.
* @return a new JButton based on the resource
*/
static JButton getButton( String resource ) {
JButton button;
CustomUIProvider customProvider = SpellChecker.getCustomUIProvider();
if( customProvider != null ) {
button = customProvider.getButton( resource );
} else {
button = new JButton( Utils.getResource( resource ) );
String tooltipKey = resource + ".tooltip";
String tooltip = Utils.getResource( tooltipKey );
if( tooltip != tooltipKey ) {
button.setToolTipText( tooltip );
}
}
return button;
}
/**
* Creates a JTextField as needed
* @return a new JTextField based on the resource
*/
static JTextField getTextField() {
JTextField textField;
CustomUIProvider customProvider = SpellChecker.getCustomUIProvider();
if( customProvider != null ) {
textField = customProvider.getTextField();
} else {
textField = new JTextField();
}
return textField;
}
/**
* Creates a JLabel as needed
*
* @param text The text to be on the label
* @return a new JLabel based on the resource
*/
static JLabel getLabel( String text ) {
JLabel label;
CustomUIProvider customProvider = SpellChecker.getCustomUIProvider();
if( customProvider != null ) {
label = customProvider.getLabel( text );
} else {
label = new JLabel( text );
}
return label;
}
/**
* Creates a JList as needed
*
* @return a new JList based on the resource
*/
static JList getList() {
CustomUIProvider customProvider = SpellChecker.getCustomUIProvider();
if( customProvider != null ) {
return customProvider.getList();
} else {
return new JList();
}
}
/**
* Set the Icon for an dialog
* @param dlg the dialog
*/
static void setDialogIcon(JDialog dlg) {
try {
Image image = ImageIO.read( dlg.getClass().getResourceAsStream( "icon.png" ) );
// setIconImage appeared in Java 6.0 so use reflection to be compatible
// with earlier JVMs. Equivalent to calling setIcomImage(image);
Class
© 2015 - 2025 Weber Informatics LLC | Privacy Policy