001: /*
002: * Copyright 2007 Paul Hinds
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.tp23.antinstaller.renderer.swing;/*
017:
018: * you may not use this file except in compliance with the License.
019: * You may obtain a copy of the License at
020: *
021: * http://www.apache.org/licenses/LICENSE-2.0
022: *
023: * Unless required by applicable law or agreed to in writing, software
024: * distributed under the License is distributed on an "AS IS" BASIS,
025: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
026: * See the License for the specific language governing permissions and
027: * limitations under the License.
028: */
029:
030: import java.awt.BorderLayout;
031: import java.awt.HeadlessException;
032: import java.util.Locale;
033:
034: import javax.swing.JFrame;
035: import javax.swing.LookAndFeel;
036: import javax.swing.UIManager;
037:
038: import org.tp23.antinstaller.InstallerContext;
039: import org.tp23.antinstaller.page.Page;
040: import org.tp23.antinstaller.runtime.SwingRunner;
041:
042: /**
043: * This Frame instance exists so refreshing the LAF and UI works and different size can be used
044: *
045: * @author teknopaul
046: *
047: */
048: public class LangSelectFrame extends JFrame implements
049: PageCompletionListener {
050:
051: private Object endinit = new Object();
052: private SimpleInputPageRenderer langRenderer = new PrePageRenderer();
053: private InstallerContext ctx;
054:
055: public LangSelectFrame() throws HeadlessException {
056: }
057:
058: public void init(InstallerContext ctx) {
059: this .ctx = ctx;
060: try {
061: SwingInstallerContext swingCtx = new SwingInstallerContext(
062: ctx, this );
063:
064: langRenderer.getBackButton().setEnabled(false);
065: langRenderer.getCancelButton().setEnabled(false);
066:
067: langRenderer.setContext(swingCtx);
068: Page langPage = ctx.getInstaller().getLangPage();
069: langRenderer.setPage(langPage);
070: langRenderer.setPageCompletionListener(this );
071: langRenderer.instanceInit();
072:
073: SwingRunner.setLocation(this );
074: setSize(this );
075: this .setTitle(langPage.getDisplayText());
076: this .getContentPane()
077: .add(langRenderer, BorderLayout.CENTER);
078: this .setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
079: this .show();
080:
081: synchronized (endinit) {
082: try {
083: endinit.wait();
084: } catch (InterruptedException e) {
085: // normal
086: }
087: }
088: this .dispose();
089: } catch (Exception e) {
090: ctx.log("Exception in LanguageSelectFrame");
091: if (ctx.getInstaller().isVerbose()) {
092: ctx.log(e);
093: }
094: }
095: }
096:
097: public void pageComplete(Page page) {
098: synchronized (endinit) {
099: langRenderer.updateInputFields();
100: try {
101: LookAndFeel newLaf = (LookAndFeel) UIManager
102: .getLookAndFeel().getClass().newInstance();
103: newLaf.getDefaults().setDefaultLocale(
104: Locale.getDefault());
105: UIManager.setLookAndFeel(newLaf);
106: } catch (Exception e) {
107: // We are resetting the existing LAF so it seems unlikely it will throw an exception
108: // Laf is eyecandy any way so ignore
109: ctx.log("Exception reloading LookAndFeel");
110: if (ctx.getInstaller().isVerbose()) {
111: ctx.log(e);
112: }
113: }
114: endinit.notify();
115: }
116: }
117:
118: public void pageBack(Page page) {
119: }
120:
121: public static void setSize(JFrame frame) {
122: frame.setSize(SizeConstants.PAGE_WIDTH
123: + SizeConstants.IMAGE_PANEL_WIDTH
124: - SizeConstants.IMAGE_PANEL_WIDTH + 8,
125: SizeConstants.PAGE_HEIGHT / 2
126: - SizeConstants.TITLE_PANEL_HEIGHT);
127: }
128:
129: }
|