List of usage examples for java.text NumberFormat getInstance
public static NumberFormat getInstance(Locale inLocale)
From source file:com.aionemu.commons.utils.concurrent.RunnableStatsManager.java
@SuppressWarnings("rawtypes") public static void dumpClassStats(final SortBy sortBy) { final List<MethodStat> methodStats = new ArrayList<MethodStat>(); synchronized (RunnableStatsManager.class) { for (ClassStat classStat : classStats.values()) for (MethodStat methodStat : classStat.methodStats) if (methodStat.count > 0) methodStats.add(methodStat); }/*from w w w .ja v a 2 s.co m*/ if (sortBy != null) Collections.sort(methodStats, sortBy.comparator); final List<String> lines = new ArrayList<String>(); lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); lines.add("<entries>"); lines.add("\t<!-- This XML contains statistics about execution times. -->"); lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->"); final String[][] values = new String[SortBy.VALUES.length][methodStats.size()]; final int[] maxLength = new int[SortBy.VALUES.length]; for (int i = 0; i < SortBy.VALUES.length; i++) { final SortBy sort = SortBy.VALUES[i]; for (int k = 0; k < methodStats.size(); k++) { final Comparable c = sort.getComparableValueOf(methodStats.get(k)); final String value; if (c instanceof Number) value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue()); else value = String.valueOf(c); values[i][k] = value; maxLength[i] = Math.max(maxLength[i], value.length()); } } for (int k = 0; k < methodStats.size(); k++) { StringBuilder sb = new StringBuilder(); sb.append("\t<entry "); EnumSet<SortBy> set = EnumSet.allOf(SortBy.class); if (sortBy != null) { switch (sortBy) { case NAME: case METHOD: appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k], maxLength[SortBy.NAME.ordinal()]); set.remove(SortBy.NAME); appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k], maxLength[SortBy.METHOD.ordinal()]); set.remove(SortBy.METHOD); break; default: appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]); set.remove(sortBy); break; } } for (SortBy sort : SortBy.VALUES) if (set.contains(sort)) appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]); sb.append("/>"); lines.add(sb.toString()); } lines.add("</entries>"); PrintStream ps = null; try { ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log"); for (String line : lines) ps.println(line); } catch (Exception e) { log.warn("", e); } finally { IOUtils.closeQuietly(ps); } }
From source file:com.l2jfree.util.concurrent.RunnableStatsManager.java
public static void dumpClassStats(final SortBy sortBy) { final List<MethodStat> methodStats = new ArrayList<MethodStat>(); synchronized (RunnableStatsManager.class) { for (ClassStat classStat : _classStats.values()) for (MethodStat methodStat : classStat._methodStats) if (methodStat._count > 0) methodStats.add(methodStat); }/*from w w w . ja v a 2s .c o m*/ if (sortBy != null) Collections.sort(methodStats, sortBy._comparator); final List<String> lines = new ArrayList<String>(); lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); lines.add("<entries>"); lines.add("\t<!-- This XML contains statistics about execution times. -->"); lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->"); final String[][] values = new String[SortBy.VALUES.length][methodStats.size()]; final int[] maxLength = new int[SortBy.VALUES.length]; for (int i = 0; i < SortBy.VALUES.length; i++) { final SortBy sort = SortBy.VALUES[i]; for (int k = 0; k < methodStats.size(); k++) { final Comparable c = sort.getComparableValueOf(methodStats.get(k)); final String value; if (c instanceof Number) value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue()); else value = String.valueOf(c); values[i][k] = value; maxLength[i] = Math.max(maxLength[i], value.length()); } } for (int k = 0; k < methodStats.size(); k++) { StringBuilder sb = new StringBuilder(); sb.append("\t<entry "); EnumSet<SortBy> set = EnumSet.allOf(SortBy.class); if (sortBy != null) { switch (sortBy) { case NAME: case METHOD: appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k], maxLength[SortBy.NAME.ordinal()]); set.remove(SortBy.NAME); appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k], maxLength[SortBy.METHOD.ordinal()]); set.remove(SortBy.METHOD); break; default: appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]); set.remove(sortBy); break; } } for (SortBy sort : SortBy.VALUES) if (set.contains(sort)) appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]); sb.append("/>"); lines.add(sb.toString()); } lines.add("</entries>"); PrintStream ps = null; try { ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log"); for (String line : lines) ps.println(line); } catch (Exception e) { _log.warn("", e); } finally { IOUtils.closeQuietly(ps); } }
From source file:com.aionlightning.commons.utils.concurrent.RunnableStatsManager.java
public static void dumpClassStats(final SortBy sortBy) { final List<MethodStat> methodStats = new ArrayList<MethodStat>(); synchronized (RunnableStatsManager.class) { for (ClassStat classStat : classStats.values()) for (MethodStat methodStat : classStat.methodStats) if (methodStat.count > 0) methodStats.add(methodStat); }//from w w w. j a v a 2s . c o m if (sortBy != null) Collections.sort(methodStats, sortBy.comparator); final List<String> lines = new ArrayList<String>(); lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); lines.add("<entries>"); lines.add("\t<!-- This XML contains statistics about execution times. -->"); lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->"); final String[][] values = new String[SortBy.VALUES.length][methodStats.size()]; final int[] maxLength = new int[SortBy.VALUES.length]; for (int i = 0; i < SortBy.VALUES.length; i++) { final SortBy sort = SortBy.VALUES[i]; for (int k = 0; k < methodStats.size(); k++) { @SuppressWarnings("rawtypes") final Comparable c = sort.getComparableValueOf(methodStats.get(k)); final String value; if (c instanceof Number) value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue()); else value = String.valueOf(c); values[i][k] = value; maxLength[i] = Math.max(maxLength[i], value.length()); } } for (int k = 0; k < methodStats.size(); k++) { StringBuilder sb = new StringBuilder(); sb.append("\t<entry "); EnumSet<SortBy> set = EnumSet.allOf(SortBy.class); if (sortBy != null) { switch (sortBy) { case NAME: case METHOD: appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k], maxLength[SortBy.NAME.ordinal()]); set.remove(SortBy.NAME); appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k], maxLength[SortBy.METHOD.ordinal()]); set.remove(SortBy.METHOD); break; default: appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]); set.remove(sortBy); break; } } for (SortBy sort : SortBy.VALUES) if (set.contains(sort)) appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]); sb.append("/>"); lines.add(sb.toString()); } lines.add("</entries>"); PrintStream ps = null; try { ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log"); for (String line : lines) ps.println(line); } catch (Exception e) { log.warn("", e); } finally { IOUtils.closeQuietly(ps); } }
From source file:com.google.android.apps.santatracker.doodles.tilt.SwimmingFragment.java
@Override protected void firstPassLoadOnUiThread() { final FrameLayout.LayoutParams wrapperLP = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);/*w w w.j a v a2 s.com*/ final SwimmingFragment that = this; scoreView = getScoreView(); pauseView = getPauseView(); int diveViewBottomMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_bottom); int diveViewStartMargin = (int) context.getResources().getDimension(R.dimen.dive_margin_left); int diveViewSize = (int) context.getResources().getDimension(R.dimen.dive_image_size); FrameLayout.LayoutParams diveViewLP = new LayoutParams(diveViewSize, diveViewSize); diveViewLP.setMargins(diveViewStartMargin, 0, 0, diveViewBottomMargin); diveViewLP.gravity = Gravity.BOTTOM | Gravity.LEFT; if (VERSION.SDK_INT >= 17) { diveViewLP.setMarginStart(diveViewStartMargin); } diveView = new DiveView(context); countdownView = new TextView(context); countdownView.setGravity(Gravity.CENTER); countdownView.setTextColor(context.getResources().getColor(R.color.ui_text_yellow)); countdownView.setTypeface(Typeface.DEFAULT_BOLD); countdownView.setText("0"); countdownView.setVisibility(View.INVISIBLE); Locale locale = context.getResources().getConfiguration().locale; countdownView.setText(NumberFormat.getInstance(locale).format(3)); Point screenDimens = AndroidUtils.getScreenSize(); UIUtil.fitToBounds(countdownView, screenDimens.x / 10, screenDimens.y / 10); LinearLayout gameView = new LinearLayout(context); gameView.setOrientation(LinearLayout.VERTICAL); // Add game view. swimmingView = new SwimmingView(context); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 7); gameView.addView(swimmingView, lp); if (editorMode) { LinearLayout buttonWrapper = new LinearLayout(context); buttonWrapper.setOrientation(LinearLayout.HORIZONTAL); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); gameView.addView(buttonWrapper, lp); resetButton = getButton(R.string.reset_level, new OnClickListener() { @Override public void onClick(View v) { SwimmingModel level = levelManager.loadDefaultLevel(); initializeLevel(level, false); getActivity().getSharedPreferences(context.getString(R.string.swimming), Context.MODE_PRIVATE) .edit().putString(CURRENT_LEVEL_KEY, null).commit(); } }); deleteButton = getButton(R.string.delete_levels, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new DeleteLevelDialogFragment(); dialogFragment.show(getActivity().getFragmentManager(), "delete"); } }); loadButton = getButton(R.string.load_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new LoadLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "load"); } }); saveButton = getButton(R.string.save_level, new OnClickListener() { @Override public void onClick(View v) { DialogFragment dialogFragment = new SaveLevelDialogFragment(that); dialogFragment.show(getActivity().getFragmentManager(), "save"); } }); collisionModeButton = new ToggleButton(context); collisionModeButton.setText(R.string.scenery_mode); collisionModeButton.setTextOff(context.getString(R.string.scenery_mode)); collisionModeButton.setTextOn(context.getString(R.string.collision_mode)); collisionModeButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.collisionMode = isChecked; } }); lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT, 1); buttonWrapper.addView(deleteButton, lp); buttonWrapper.addView(resetButton, lp); buttonWrapper.addView(loadButton, lp); buttonWrapper.addView(saveButton, lp); buttonWrapper.addView(collisionModeButton, lp); } sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (accelerometerSensor == null) { // TODO: The game won't be playable without this, so what should we do? Log.d(TAG, "Accelerometer sensor is null"); } displayRotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getRotation(); wrapper.addView(gameView, 0, wrapperLP); wrapper.addView(countdownView, 1); wrapper.addView(diveView, 2, diveViewLP); wrapper.addView(scoreView, 3); wrapper.addView(pauseView, 4); }
From source file:de.uka.aifb.com.systemDynamics.gui.ModelExecutionChartPanel.java
/** * Creates panel./*from w ww . ja va 2 s .c om*/ */ private void createPanel() { setLayout(new BorderLayout()); // CENTER: chart ChartPanel chartPanel = new ChartPanel(createChart()); // no context menu chartPanel.setPopupMenu(null); // not zoomable chartPanel.setMouseZoomable(false); add(chartPanel, BorderLayout.CENTER); // LINE_END: series table JPanel tablePanel = new JPanel(new GridBagLayout()); String[] columnNames = { messages.getString("ModelExecutionChartPanel.Table.ColumnNames.ExtraAxis"), messages.getString("ModelExecutionChartPanel.Table.ColumnNames.LevelNode") }; final MyTableModel tableModel = new MyTableModel(columnNames, xySeriesArray.length); for (int i = 0; i < xySeriesArray.length; i++) { tableModel.addEntry((String) xySeriesArray[i].getKey()); } JTable table = new JTable(tableModel); table.setRowSelectionAllowed(false); JScrollPane tableScrollPane = new JScrollPane(table); int width = (int) Math.min(300, table.getPreferredSize().getWidth()); int height = (int) Math.min(200, table.getPreferredSize().getHeight()); tableScrollPane.getViewport().setPreferredSize(new Dimension(width, height)); tableScrollPane.setMaximumSize(tableScrollPane.getViewport().getPreferredSize()); axesButton = new JButton(messages.getString("ModelExecutionChartPanel.AxesButton.Text")); axesButton.setToolTipText(messages.getString("ModelExecutionChartPanel.AxesButton.ToolTipText")); axesButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // create XYSeriesCollections (and renderer) XYSeriesCollection standardData = new XYSeriesCollection(); XYLineAndShapeRenderer standardRenderer = new XYLineAndShapeRenderer(true, false); LinkedList<XYSeriesCollection> extraDataList = new LinkedList<XYSeriesCollection>(); LinkedList<XYLineAndShapeRenderer> extraRendererList = new LinkedList<XYLineAndShapeRenderer>(); for (int i = 0; i < tableModel.getRowCount(); i++) { if (tableModel.getValueAt(i, 0).equals(Boolean.FALSE)) { standardData.addSeries(xySeriesArray[i]); standardRenderer.setSeriesPaint(standardData.getSeriesCount() - 1, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]); } else { // extra axis XYSeriesCollection extraData = new XYSeriesCollection(); extraData.addSeries(xySeriesArray[i]); extraDataList.add(extraData); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); extraRendererList.add(renderer); renderer.setSeriesPaint(0, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]); } } LinkedList<XYSeriesCollection> dataList = new LinkedList<XYSeriesCollection>(); LinkedList<XYLineAndShapeRenderer> rendererList = new LinkedList<XYLineAndShapeRenderer>(); if (!standardData.getSeries().isEmpty()) { dataList.add(standardData); rendererList.add(standardRenderer); } for (XYSeriesCollection data : extraDataList) { dataList.add(data); } for (XYLineAndShapeRenderer renderer : extraRendererList) { rendererList.add(renderer); } // creates axes LinkedList<NumberAxis> axesList = new LinkedList<NumberAxis>(); if (!standardData.getSeries().isEmpty()) { NumberAxis axis = new NumberAxis(messages.getString("ModelExecutionChartPanel.Value")); axis.setNumberFormatOverride(NumberFormat.getInstance(locale)); axesList.add(axis); } for (XYSeriesCollection data : extraDataList) { NumberAxis axis = new NumberAxis((String) data.getSeries(0).getKey()); axis.setNumberFormatOverride(NumberFormat.getInstance(locale)); axesList.add(axis); } // store data and axes in plot XYPlot plot = chart.getXYPlot(); plot.clearRangeAxes(); plot.setRangeAxes(axesList.toArray(new NumberAxis[0])); for (int i = 0; i < plot.getDatasetCount(); i++) { plot.setDataset(i, null); } int datasetIndex = 0; Iterator<XYSeriesCollection> datasetIterator = dataList.iterator(); Iterator<XYLineAndShapeRenderer> rendererIterator = rendererList.iterator(); while (datasetIterator.hasNext()) { plot.setDataset(datasetIndex, datasetIterator.next()); plot.setRenderer(datasetIndex, rendererIterator.next()); datasetIndex++; } for (int i = 0; i < plot.getDatasetCount(); i++) { plot.mapDatasetToRangeAxis(i, i); } } }); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 0; c.insets = new Insets(0, 0, 10, 0); tablePanel.add(tableScrollPane, c); c.gridx = 0; c.gridy = 1; tablePanel.add(axesButton, c); add(tablePanel, BorderLayout.LINE_END); // PAGE_END: number of rounds and execution button JPanel commandPanel = new JPanel(); commandPanel.add(new JLabel(messages.getString("ModelExecutionChartPanel.NumberRounds"))); final JTextField numberRoundsField = new JTextField("1", 5); numberRoundsField.addFocusListener(this); commandPanel.add(numberRoundsField); executionButton = new JButton(messages.getString("ModelExecutionChartPanel.ExecutionButton.Text")); executionButton.setToolTipText(messages.getString("ModelExecutionChartPanel.ExecutionButton.ToolTipText")); executionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int numberRounds = 0; boolean correctNumber = false; try { numberRounds = integerNumberFormatter.parse(numberRoundsField.getText()).intValue(); } catch (ParseException parseExcep) { // do nothing } if (numberRounds >= 1) { correctNumber = true; } if (correctNumber) { ModelExecutionThread executionThread = new ModelExecutionThread(numberRounds); executionThread.start(); } else { JOptionPane.showMessageDialog(null, messages.getString("ModelExecutionChartPanel.Error.Message"), messages.getString("ModelExecutionChartPanel.Error.Title"), JOptionPane.ERROR_MESSAGE); } } }); commandPanel.add(executionButton); add(commandPanel, BorderLayout.PAGE_END); }
From source file:com.jeeframework.util.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a float primitive. * *@param value The value validation is being performed on. *@param locale The locale to use to parse the number (system default if * null)/*from w w w . j a va 2 s .c o m*/ *@return the converted Float value. */ public static Float formatFloat(String value, Locale locale) { Float result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getInstance(locale); } else { formatter = NumberFormat.getInstance(Locale.getDefault()); } ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= (Float.MAX_VALUE * -1) && num.doubleValue() <= Float.MAX_VALUE) { result = new Float(num.floatValue()); } } } return result; }
From source file:org.optaplanner.benchmark.impl.statistic.single.pickedmovetypestepscore.PickedMoveTypeStepScoreDiffSingleStatistic.java
private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Step score diff level " + scoreLevelIndex); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(true); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); return plot;/*from w w w .ja v a 2 s . co m*/ }
From source file:easyJ.common.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a float primitive. * /* w w w. j av a 2 s. c o m*/ * @param value * The value validation is being performed on. * @param locale * The locale to use to parse the number (system default if * null) * @return the converted Float value. */ public static Float formatFloat(String value, Locale locale) { Float result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getInstance(locale); } else { formatter = NumberFormat.getInstance(Locale.getDefault()); } ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= (Float.MAX_VALUE * -1) && num.doubleValue() <= Float.MAX_VALUE) { result = new Float(num.floatValue()); } } } return result; }
From source file:org.optaplanner.benchmark.impl.statistic.single.pickedmovetypebestscore.PickedMoveTypeBestScoreDiffSingleStatistic.java
private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Best score diff level " + scoreLevelIndex); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(true); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); return plot;//from w ww .j a v a2 s .co m }
From source file:ome.formats.importer.gui.LoginHandler.java
/** * Attempt a login//from w ww . j a v a 2 s.c o m */ public void tryLogin() { new Thread() { public void run() { if (!NEW_LOGIN) { //SplashWindow.disposeSplash(); viewer.setVisible(true); // Values should already be set on config. } else { config.username.set(lc.getUserName()); config.password.set(lc.getPassword()); config.hostname.set(lc.getHostName()); config.port.set(lc.getPort()); config.group.set(lc.getGroup()); config.encryptedConnection.set(lc.isEncrypted()); } viewer.getStatusBar().setStatusIcon("gfx/server_trying16.png", "Trying to connect to " + config.hostname.get()); viewer.getStatusBar().setProgress(true, -1, "connecting...."); try { if (isValidLogin()) { String serverVersion = store.getServiceFactory().getConfigService().getVersion(); if (!checkClientServerCompatibility(serverVersion, config.getIniVersionNumber())) { JOptionPane.showMessageDialog(viewer, "Client and server are not compatible \n" + "client version:" + config.getIniVersionNumber() + "\n" + "server version:" + serverVersion + "\n" + "try to log in again."); viewer.appendToOutput("> Incompatible client-server. " + "Try to relog.\n"); viewer.enableMenus(true); viewer.setLoggedIn(false); if (NEW_LOGIN) refreshNewLogin(); logout(); return; } if (NEW_LOGIN) { store.setCurrentGroup(lc.getGroup()); try { // Save login screen groups ScreenLogin.registerGroup(store.mapUserGroups()); } catch (Exception e) { log.warn("Exception on ScreenLogin.registerGroup()", e); } view.close(); viewTop.close(); viewer.setVisible(true); } config.isUpgradeNeeded(); store.logVersionInfo(config.getIniVersionNumber()); viewer.getStatusBar().setProgress(false, 0, ""); viewer.appendToOutput("> Login Successful.\n"); viewer.getFileQueueHandler().enableImports(true); log.info("Login successful!"); viewer.enableMenus(true); viewer.setImportEnabled(true); viewer.setLoggedIn(true); notifyObservers(new ImportEvent.LOGGED_IN()); String group = store.getDefaultGroupName(); int groupLevel = store.getDefaultGroupLevel(); notifyObservers(new ImportEvent.GROUP_SET(group, groupLevel)); // if this fails, using the old server without repositorySpace try { long freeSpace = store.getRepositorySpace(); NumberFormat formatter = NumberFormat.getInstance(Locale.US); String freeMB = formatter.format(freeSpace / 1000); viewer.getStatusBar().setStatusIcon("gfx/server_connect16.png", "Connected to " + config.hostname.get() + " (" + group + "). Free space: " + freeMB + " MB."); return; } catch (Exception e) { log.error("Exception retrieving repository free space.", e); viewer.getStatusBar().setStatusIcon("gfx/server_connect16.png", "Connected to " + config.hostname.get() + " (" + group + ")."); return; } } else { if (NEW_LOGIN) view.setAlwaysOnTop(false); log.info("Login failed!"); viewer.getStatusBar().setProgress(false, 0, ""); viewer.getStatusBar().setStatusIcon("gfx/error_msg16.png", "Incorrect username/password. Server login failed, please try to " + "log in again."); JOptionPane.showMessageDialog(viewer, "Incorrect username/password. Server login \nfailed, please " + "try to log in again."); viewer.appendToOutput("> Login failed. Try to relog.\n"); viewer.enableMenus(true); viewer.setLoggedIn(false); if (NEW_LOGIN) refreshNewLogin(); return; } } catch (Exception e) { log.error("Exception in LoginHandler.", e); viewer.getStatusBar().setProgress(false, 0, ""); viewer.getStatusBar().setStatusIcon("gfx/error_msg16.png", "Server connection to " + config.hostname.get() + " failed. " + "Please try again."); if (NEW_LOGIN) view.setAlwaysOnTop(false); JOptionPane.showMessageDialog(viewer, "\nThe application failed to log in. The hostname may be wrong or " + "\nthe server may be offline." + "\n\nPlease try again."); viewer.appendToOutput("> Login failed. Try to relog.\n"); viewer.enableMenus(true); viewer.setLoggedIn(false); if (NEW_LOGIN) refreshNewLogin(); return; } } }.start(); }