001 /* 002 * Copyright (C) 2008-2010 by Holger Arndt 003 * 004 * This file is part of the Universal Java Matrix Package (UJMP). 005 * See the NOTICE file distributed with this work for additional 006 * information regarding copyright ownership and licensing. 007 * 008 * UJMP is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation; either version 2 011 * of the License, or (at your option) any later version. 012 * 013 * UJMP is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU Lesser General Public License for more details. 017 * 018 * You should have received a copy of the GNU Lesser General Public 019 * License along with UJMP; if not, write to the 020 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 021 * Boston, MA 02110-1301 USA 022 */ 023 024 package org.ujmp.gui.util; 025 026 import javax.swing.JOptionPane; 027 028 import org.ujmp.core.Coordinates; 029 import org.ujmp.core.util.MathUtil; 030 031 public abstract class GUIUtil { 032 033 public static Object getObject(String message, Object... objects) { 034 return objects[JOptionPane.showOptionDialog(null, message, message, 035 JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, 036 objects, null)]; 037 } 038 039 public static int getInt(String message, int min, int max) { 040 int i = Integer.MAX_VALUE; 041 while (i == Integer.MAX_VALUE) { 042 String s = JOptionPane.showInputDialog(message + " (" + min 043 + " to " + max + ")"); 044 try { 045 i = Integer.parseInt(s); 046 } catch (Exception e) { 047 } 048 } 049 return i; 050 } 051 052 public static double getDouble(String message, double min, double max) { 053 double i = Double.NaN; 054 while (MathUtil.isNaNOrInfinite(i)) { 055 String s = JOptionPane.showInputDialog(message + " (" + min 056 + " to " + max + ")"); 057 try { 058 i = Double.parseDouble(s); 059 } catch (Exception e) { 060 } 061 } 062 return i; 063 } 064 065 public static String getString(String message) { 066 return JOptionPane.showInputDialog(message); 067 } 068 069 public static boolean getBoolean(String message) { 070 int i = JOptionPane.showConfirmDialog(null, message, message, 071 JOptionPane.YES_NO_OPTION); 072 return JOptionPane.YES_OPTION == i; 073 } 074 075 public static long[] getSize(String message) { 076 long size[] = null; 077 while (size == null) { 078 String s = getString(message); 079 try { 080 size = Coordinates.parseString(s); 081 } catch (Exception e) { 082 } 083 } 084 return size; 085 } 086 087 }