001: /*
002: * $Id: IzPanel.java 2063 2008-02-26 13:25:57Z pskowronek $
003: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
004: *
005: * http://izpack.org/
006: * http://izpack.codehaus.org/
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: */
020: package com.izforge.izpack.installer;
021:
022: import com.izforge.izpack.Panel;
023: import com.izforge.izpack.gui.LabelFactory;
024: import com.izforge.izpack.gui.LayoutConstants;
025: import com.izforge.izpack.util.AbstractUIHandler;
026: import com.izforge.izpack.util.Debug;
027: import com.izforge.izpack.util.MultiLineLabel;
028: import com.izforge.izpack.util.VariableSubstitutor;
029: import net.n3.nanoxml.XMLElement;
030:
031: import javax.swing.*;
032: import javax.swing.plaf.metal.MetalLookAndFeel;
033: import java.awt.*;
034:
035: /**
036: * Defines the base class for the IzPack panels. Any panel should be a subclass of it and should
037: * belong to the <code>com.izforge.izpack.panels</code> package.
038: * Since IzPack version 3.9 the layout handling will be delegated to the class
039: * LayoutHelper which can be accessed by <code>getLayoutHelper</code>.
040: * There are some layout helper methods in this class which will be exist some time longer,
041: * but they are deprecated. At a redesign or new panel use the layout helper.
042: * There is a special layout manager for IzPanels. This layout manager will be supported
043: * by the layout helper. There are some points which should be observed at layouting.
044: * One point e.g. is the anchor. All IzPanels have to be able to use different anchors, as
045: * minimum CENTER and NORTHWEST.
046: * To use a consistent appearance use this special layout manger and not others.
047: *
048: * @author Julien Ponge
049: * @author Klaus Bartz
050: */
051: public class IzPanel extends JPanel implements AbstractUIHandler,
052: LayoutConstants {
053:
054: private static final long serialVersionUID = 3256442495255786038L;
055:
056: /** The helper object which handles layout */
057: protected LayoutHelper layoutHelper;
058:
059: /** The component which should get the focus at activation */
060: protected Component initialFocus = null;
061:
062: /**
063: * The installer internal data (actually a melting-pot class with all-public fields.
064: */
065: protected InstallData idata;
066:
067: /** The parent IzPack installer frame. */
068: protected InstallerFrame parent;
069:
070: /** i.e. "com.izforge.izpack.panels.HelloPanel" */
071: protected String myFullClassname;
072:
073: /** myClassname=i.e "FinishPanel" */
074: protected String myClassname;
075:
076: /** i.e. "FinishPanel." useFull for getString() */
077: protected String myPrefix;
078:
079: /** internal headline string */
080: protected String headline;
081:
082: /** internal headline Label */
083: protected JLabel headLineLabel;
084:
085: /** Is this panel general hidden or not */
086: protected boolean hidden;
087:
088: /** HEADLINE = "headline" */
089: public final static String HEADLINE = "headline";
090:
091: /** X_ORIGIN = 0 */
092: public final static int X_ORIGIN = 0;
093:
094: /** Y_ORIGIN = 0 */
095: public final static int Y_ORIGIN = 0;
096: /** D = "." ( dot ) */
097: public final static String D = ".";
098:
099: /** d = D */
100: public final static String d = D;
101:
102: /** COLS_1 = 1 */
103: public final static int COLS_1 = 1;
104:
105: /** ROWS_1 = 1 */
106: public final static int ROWS_1 = 1;
107:
108: /**
109: * Information about the panel
110: */
111: public Panel metadata;
112:
113: /**
114: * The constructor.
115: *
116: * @param parent The parent IzPack installer frame.
117: * @param idata The installer internal data.
118: */
119: public IzPanel(InstallerFrame parent, InstallData idata) {
120: this (parent, idata, (LayoutManager2) null);
121: }
122:
123: /**
124: * Creates a new IzPanel object with the given layout manager. Valid layout manager are the
125: * IzPanelLayout and the GridBagLayout. New panels should be use the IzPanelLaout.
126: * If lm is null, no layout manager will be created or initialized.
127: * @param parent The parent IzPack installer frame.
128: * @param idata The installer internal data.
129: * @param lm layout manager to be used with this IzPanel
130: */
131: public IzPanel(InstallerFrame parent, InstallData idata,
132: LayoutManager2 lm) {
133: super ();
134: init(parent, idata);
135: if (lm != null)
136: getLayoutHelper().startLayout(lm);
137: }
138:
139: /**
140: * Creates a new IzPanel object.
141: *
142: * @param parent the Parent Frame
143: * @param idata Installers Runtime Data Set
144: * @param iconName The Headline IconName
145: */
146: public IzPanel(InstallerFrame parent, InstallData idata,
147: String iconName) {
148: this (parent, idata, iconName, -1);
149: }
150:
151: /**
152: * The constructor with Icon.
153: *
154: * @param parent The parent IzPack installer frame.
155: * @param idata The installer internal data.
156: * @param iconName A iconname to show as left oriented headline-leading Icon.
157: * @param instance An instance counter
158: */
159: public IzPanel(InstallerFrame parent, InstallData idata,
160: String iconName, int instance) {
161: this (parent, idata);
162: buildHeadline(iconName, instance);
163: }
164:
165: /**
166: * Build the IzPanel internal Headline. If an external headline#
167: * is used, this method returns immediately with false.
168: * Allows also to display a leading Icon for the PanelHeadline.
169: * This Icon can also be different if the panel has more than one Instances.
170: * The UserInputPanel is one of these Candidates.
171: *
172: * by marc.eppelmann@gmx.de
173: *
174: * @param imageIconName an Iconname
175: * @param instanceNumber an panel instance
176: *
177: * @return true if successful build
178: */
179: protected boolean buildHeadline(String imageIconName,
180: int instanceNumber) {
181: boolean result = false;
182: if (parent.isHeading(this ))
183: return (false);
184:
185: // TODO: proteced instancenumber
186: // TODO: is to be validated
187: // TODO:
188: // TODO: first Test if a Resource for your protected Instance exists.
189: String headline;
190: String headlineSearchBaseKey = myClassname + d + "headline"; // Results for example in "ShortcutPanel.headline" :
191:
192: if (instanceNumber > -1) // Search for Results for example in "ShortcutPanel.headline.1, 2, 3 etc." :
193: {
194: String instanceSearchKey = headlineSearchBaseKey + d
195: + Integer.toString(instanceNumber);
196:
197: String instanceHeadline = getString(instanceSearchKey);
198:
199: if (Debug.isLOG()) {
200: System.out.println("found headline: "
201: + instanceHeadline + d + " for instance # "
202: + instanceNumber);
203: }
204: if (!instanceSearchKey.equals(instanceHeadline)) {
205: headline = instanceHeadline;
206: } else {
207: headline = getString(headlineSearchBaseKey);
208: }
209: } else {
210: headline = getString(headlineSearchBaseKey);
211: }
212:
213: if (headline != null) {
214: if ((imageIconName != null) && !"".equals(imageIconName)) {
215: headLineLabel = new JLabel(headline,
216: getImageIcon(imageIconName),
217: SwingConstants.LEADING);
218: } else {
219: headLineLabel = new JLabel(headline);
220: }
221:
222: Font font = headLineLabel.getFont();
223: float size = font.getSize();
224: int style = 0;
225: font = font.deriveFont(style, (size * 1.5f));
226: headLineLabel.setFont(font);
227:
228: GridBagConstraints gbc = new GridBagConstraints();
229:
230: gbc.gridx = 0;
231: gbc.gridy = 0;
232: gbc.gridwidth = 1;
233: gbc.gridheight = 1;
234:
235: gbc.fill = GridBagConstraints.HORIZONTAL;
236: gbc.anchor = GridBagConstraints.WEST;
237: gbc.insets = new Insets(0, 0, 0, 0);
238: headLineLabel.setName(HEADLINE);
239: ((GridBagLayout) getLayout()).addLayoutComponent(
240: headLineLabel, gbc);
241:
242: add(headLineLabel);
243: }
244:
245: return result;
246: }
247:
248: /**
249: * Gets a language Resource String from the parent, which holds these global resource.
250: *
251: * @param key The Search key
252: *
253: * @return The Languageresource or the key if not found.
254: */
255: public String getString(String key) {
256: return parent.langpack.getString(key);
257: }
258:
259: /**
260: * Gets a named image icon
261: *
262: * @param iconName a valid image icon
263: *
264: * @return the icon
265: */
266: public ImageIcon getImageIcon(String iconName) {
267: return parent.icons.getImageIcon(iconName);
268: }
269:
270: /**
271: * Inits and sets the internal layout helper object.
272: */
273: protected void initLayoutHelper() {
274: layoutHelper = new LayoutHelper(this );
275: }
276:
277: /**
278: * Gets and fills the classname fields
279: */
280: protected void getClassName() {
281: myFullClassname = getClass().getName();
282: myClassname = myFullClassname.substring(myFullClassname
283: .lastIndexOf(".") + 1);
284: myPrefix = myClassname + ".";
285: }
286:
287: /**
288: * Internal init method
289: *
290: * @param parent the parent frame
291: * @param idata installers runtime dataset
292: */
293: protected void init(InstallerFrame parent, InstallData idata) {
294: getClassName();
295:
296: this .idata = idata;
297: this .parent = parent;
298: // To get the Panel object via idata is a hack because InstallData will
299: // be hold global data, not panel specific data. But the Panel object will
300: // be needed in the constructor of some derived classes. And to expand the
301: // constructor is also not a good way because all derived classes have to
302: // change then the signature. Also the custem IzPanels elswhere. Therefore
303: // this hack...
304: // Problems with this hack will be exist if more than one threads calls the
305: // constructors of derived clases. This is not the case.
306: this .metadata = idata.currentPanel;
307: idata.currentPanel = null;
308: initLayoutHelper();
309:
310: }
311:
312: /**
313: * Indicates wether the panel has been validated or not. The installer won't let the user go
314: * further through the installation process until the panel is validated. Default behaviour is
315: * to return <code>true</code>.
316: *
317: * @return A boolean stating whether the panel has been validated or not.
318: */
319: public boolean isValidated() {
320: return true;
321: }
322:
323: /**
324: * This method is called when the panel becomes active. Default is to do nothing : feel free to
325: * implement what you need in your subclasses. A panel becomes active when the user reaches it
326: * during the installation process.
327: */
328: public void panelActivate() {
329: }
330:
331: /**
332: * This method is called when the panel gets desactivated, when the user switches to the next
333: * panel. By default it doesn't do anything.
334: */
335: public void panelDeactivate() {
336: }
337:
338: /**
339: * Asks the panel to set its own XML data that can be brought back for an automated installation
340: * process. Use it as a blackbox if your panel needs to do something even in automated mode.
341: *
342: * @param panelRoot The XML root element of the panels blackbox tree.
343: */
344: public void makeXMLData(XMLElement panelRoot) {
345: }
346:
347: /**
348: * Ask the user a question.
349: *
350: * @param title Message title.
351: * @param question The question.
352: * @param choices The set of choices to present.
353: *
354: * @return The user's choice.
355: *
356: * @see AbstractUIHandler#askQuestion(String, String, int)
357: */
358: public int askQuestion(String title, String question, int choices) {
359: return askQuestion(title, question, choices, -1);
360: }
361:
362: /**
363: * Ask the user a question.
364: *
365: * @param title Message title.
366: * @param question The question.
367: * @param choices The set of choices to present.
368: * @param default_choice The default choice. (-1 = no default choice)
369: *
370: * @return The user's choice.
371: * @see AbstractUIHandler#askQuestion(String, String, int, int)
372: */
373: public int askQuestion(String title, String question, int choices,
374: int default_choice) {
375: int jo_choices = 0;
376:
377: if (choices == AbstractUIHandler.CHOICES_YES_NO)
378: jo_choices = JOptionPane.YES_NO_OPTION;
379: else if (choices == AbstractUIHandler.CHOICES_YES_NO_CANCEL)
380: jo_choices = JOptionPane.YES_NO_CANCEL_OPTION;
381:
382: int user_choice = JOptionPane.showConfirmDialog(this , question,
383: title, jo_choices, JOptionPane.QUESTION_MESSAGE);
384:
385: if (user_choice == JOptionPane.CANCEL_OPTION)
386: return AbstractUIHandler.ANSWER_CANCEL;
387:
388: if (user_choice == JOptionPane.YES_OPTION)
389: return AbstractUIHandler.ANSWER_YES;
390:
391: if (user_choice == JOptionPane.CLOSED_OPTION)
392: return AbstractUIHandler.ANSWER_NO;
393:
394: if (user_choice == JOptionPane.NO_OPTION)
395: return AbstractUIHandler.ANSWER_NO;
396:
397: return default_choice;
398: }
399:
400: public boolean emitNotificationFeedback(String message) {
401: return (JOptionPane.showConfirmDialog(this , message,
402: idata.langpack.getString("installer.Message"),
403: JOptionPane.WARNING_MESSAGE,
404: JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION);
405: }
406:
407: /**
408: * Notify the user about something.
409: *
410: * @param message The notification.
411: */
412: public void emitNotification(String message) {
413: JOptionPane.showMessageDialog(this , message);
414: }
415:
416: /**
417: * Warn the user about something.
418: *
419: * @param message The warning message.
420: */
421: public boolean emitWarning(String title, String message) {
422: return (JOptionPane.showConfirmDialog(this , message, title,
423: JOptionPane.WARNING_MESSAGE,
424: JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION);
425:
426: }
427:
428: /**
429: * Notify the user of some error.
430: *
431: * @param message The error message.
432: */
433: public void emitError(String title, String message) {
434: JOptionPane.showMessageDialog(this , message, title,
435: JOptionPane.ERROR_MESSAGE);
436: }
437:
438: /**
439: * Returns the component which should be get the focus at activation of this panel.
440: *
441: * @return the component which should be get the focus at activation of this panel
442: */
443: public Component getInitialFocus() {
444: return initialFocus;
445: }
446:
447: /**
448: * Sets the component which should be get the focus at activation of this panel.
449: *
450: * @param component which should be get the focus at activation of this panel
451: */
452: public void setInitialFocus(Component component) {
453: initialFocus = component;
454: }
455:
456: /**
457: * Calls the langpack of parent InstallerFrame for the String <tt>RuntimeClassName.subkey</tt>.
458: * Do not add a point infront of subkey, it is always added in this method.
459: * If <tt>RuntimeClassName.subkey</tt> is not found, the super class name will be used
460: * until it is <tt>IzPanel</tt>. If no key will be found, null returns.
461: *
462: * @param subkey the subkey for the string which should be returned
463: * @return the founded string
464: */
465: public String getI18nStringForClass(String subkey) {
466: String retval = null;
467: Class clazz = this .getClass();
468: while (retval == null && !clazz.getName().endsWith(".IzPanel")) {
469: retval = getI18nStringForClass(clazz.getName(), subkey,
470: null);
471: clazz = clazz.getSuperclass();
472: }
473: return (retval);
474: }
475:
476: /**
477: * Calls the langpack of parent InstallerFrame for the String <tt>RuntimeClassName.subkey</tt>.
478: * Do not add a point infront of subkey, it is always added in this method.
479: * If no key will be found the key or - if alternate class is null - null returns.
480: *
481: * @param subkey the subkey for the string which should be returned
482: * @param alternateClass the short name of the class which should be used if no string is
483: * present with the runtime class name
484: * @return the founded string
485: */
486: public String getI18nStringForClass(String subkey,
487: String alternateClass) {
488: return (getI18nStringForClass(getClass().getName(), subkey,
489: alternateClass));
490:
491: }
492:
493: private String getI18nStringForClass(String curClassName,
494: String subkey, String alternateClass) {
495:
496: int nameStart = curClassName.lastIndexOf('.') + 1;
497: curClassName = curClassName.substring(nameStart, curClassName
498: .length());
499: StringBuffer buf = new StringBuffer();
500: buf.append(curClassName).append(".").append(subkey);
501: String fullkey = buf.toString();
502: String panelid = null;
503: if (getMetadata() != null) {
504: panelid = getMetadata().getPanelid();
505: }
506: String retval = null;
507: if (panelid != null) {
508: buf.append(".");
509: buf.append(panelid);
510: retval = parent.langpack.getString(buf.toString());
511: }
512: if (retval == null || retval.startsWith(fullkey))
513: retval = parent.langpack.getString(fullkey);
514: if (retval == null || retval.startsWith(fullkey)) {
515: if (alternateClass == null)
516: return (null);
517: buf.delete(0, buf.length());
518: buf.append(alternateClass).append(".").append(subkey);
519: retval = parent.langpack.getString(buf.toString());
520: }
521: if (retval != null && retval.indexOf('$') > -1) {
522: VariableSubstitutor substitutor = new VariableSubstitutor(
523: idata.getVariables());
524: retval = substitutor.substitute(retval, null);
525: }
526: return (retval);
527: }
528:
529: /**
530: * Returns the parent of this IzPanel (which is a InstallerFrame).
531: *
532: * @return the parent of this IzPanel
533: */
534: public InstallerFrame getInstallerFrame() {
535: return (parent);
536: }
537:
538: // ------------- Helper for common used components ----- START ---
539:
540: /**
541: * Creates a label via LabelFactory using iconId, pos and method getI18nStringForClass for
542: * resolving the text to be used. If the icon id is null, the label will be created also.
543: *
544: * @param subkey the subkey which should be used for resolving the text
545: * @param alternateClass the short name of the class which should be used if no string is
546: * present with the runtime class name
547: * @param iconId id string for the icon
548: * @param pos horizontal alignment
549: * @return the newly created label
550: */
551: public JLabel createLabel(String subkey, String alternateClass,
552: String iconId, int pos) {
553: ImageIcon ii = (iconId != null) ? parent.icons
554: .getImageIcon(iconId) : null;
555: String msg = getI18nStringForClass(subkey, alternateClass);
556: JLabel label = LabelFactory.create(msg, ii, pos);
557: if (label != null)
558: label.setFont(getControlTextFont());
559: return (label);
560:
561: }
562:
563: /**
564: * Creates a label via LabelFactory using iconId, pos and method getI18nStringForClass for
565: * resolving the text to be used. If the icon id is null, the label will be created also. If
566: * isFullLine true a LabelFactory.FullLineLabel will be created instead of a JLabel. The
567: * difference between both classes are a different layout handling.
568: *
569: * @param subkey the subkey which should be used for resolving the text
570: * @param alternateClass the short name of the class which should be used if no string is
571: * present with the runtime class name
572: * @param iconId id string for the icon
573: * @param pos horizontal alignment
574: * @param isFullLine determines whether a FullLineLabel or a JLabel should be created
575: * @return the newly created label
576: */
577: public JLabel createLabel(String subkey, String alternateClass,
578: String iconId, int pos, boolean isFullLine) {
579: ImageIcon ii = (iconId != null) ? parent.icons
580: .getImageIcon(iconId) : null;
581: String msg = getI18nStringForClass(subkey, alternateClass);
582: JLabel label = LabelFactory.create(msg, ii, pos, isFullLine);
583: if (label != null)
584: label.setFont(getControlTextFont());
585: return (label);
586:
587: }
588:
589: /**
590: * Creates a label via LabelFactory with the given ids and the given horizontal alignment. If
591: * the icon id is null, the label will be created also. The strings are the ids for the text in
592: * langpack and the icon in icons of the installer frame.
593: *
594: * @param textId id string for the text
595: * @param iconId id string for the icon
596: * @param pos horizontal alignment
597: * @return the newly created label
598: */
599: public JLabel createLabel(String textId, String iconId, int pos) {
600: return (createLabel(textId, iconId, pos, false));
601: }
602:
603: /**
604: * Creates a label via LabelFactory with the given ids and the given horizontal alignment. If
605: * the icon id is null, the label will be created also. The strings are the ids for the text in
606: * langpack and the icon in icons of the installer frame. If isFullLine true a
607: * LabelFactory.FullLineLabel will be created instead of a JLabel. The difference between both
608: * classes are a different layout handling.
609: *
610: * @param textId id string for the text
611: * @param iconId id string for the icon
612: * @param pos horizontal alignment
613: * @param isFullLine determines whether a FullLineLabel or a JLabel should be created
614: * @return the newly created label
615: */
616: public JLabel createLabel(String textId, String iconId, int pos,
617: boolean isFullLine) {
618: ImageIcon ii = (iconId != null) ? parent.icons
619: .getImageIcon(iconId) : null;
620: JLabel label = LabelFactory.create(parent.langpack
621: .getString(textId), ii, pos, isFullLine);
622: if (label != null)
623: label.setFont(getControlTextFont());
624: return (label);
625:
626: }
627:
628: /**
629: * Creates a multi line label with the language dependent text given by the text id. The strings
630: * is the id for the text in langpack of the installer frame. The horizontal alignment will be
631: * LEFT.
632: *
633: * @param textId id string for the text
634: * @return the newly created multi line label
635: */
636: public MultiLineLabel createMultiLineLabelLang(String textId) {
637: return (createMultiLineLabel(parent.langpack.getString(textId)));
638: }
639:
640: /**
641: * Creates a multi line label with the given text. The horizontal alignment will be LEFT.
642: *
643: * @param text text to be used in the label
644: * @return the newly created multi line label
645: */
646: public MultiLineLabel createMultiLineLabel(String text) {
647: return (createMultiLineLabel(text, null, SwingConstants.LEFT));
648: }
649:
650: /**
651: * Creates a label via LabelFactory with the given text, the given icon id and the given
652: * horizontal alignment. If the icon id is null, the label will be created also. The strings are
653: * the ids for the text in langpack and the icon in icons of the installer frame.
654: *
655: * @param text text to be used in the label
656: * @param iconId id string for the icon
657: * @param pos horizontal alignment
658: * @return the created multi line label
659: */
660: public MultiLineLabel createMultiLineLabel(String text,
661: String iconId, int pos) {
662: MultiLineLabel mll = null;
663: mll = new MultiLineLabel(text, 0, 0);
664: if (mll != null)
665: mll.setFont(getControlTextFont());
666: return (mll);
667: }
668:
669: /**
670: * The Font of Labels in many cases
671: */
672: public Font getControlTextFont() {
673: return (getLAF() != null ? MetalLookAndFeel
674: .getControlTextFont() : getFont());
675: }
676:
677: protected static MetalLookAndFeel getLAF() {
678: LookAndFeel laf = UIManager.getLookAndFeel();
679: if (laf instanceof MetalLookAndFeel)
680: return ((MetalLookAndFeel) laf);
681: return (null);
682: }
683:
684: // ------------- Helper for common used components ----- END ---
685: // ------------------- Layout stuff -------------------- START ---
686: /**
687: * Returns the default GridBagConstraints of this panel.
688: *
689: * @return the default GridBagConstraints of this panel
690: * @deprecated use <code>getLayoutHelper().getDefaulConstraints</code> instead
691: */
692: public GridBagConstraints getDefaultGridBagConstraints() {
693: return (GridBagConstraints) (layoutHelper
694: .getDefaultConstraints());
695: }
696:
697: /**
698: * Sets the default GridBagConstraints of this panel to the given object.
699: *
700: * @param constraints which should be set as default for this object
701: * @deprecated use <code>getLayoutHelper().setDefaultConstraints</code> instead
702: */
703: public void setDefaultGridBagConstraints(
704: GridBagConstraints constraints) {
705: layoutHelper.setDefaultConstraints(constraints);
706: }
707:
708: /**
709: * Resets the grid counters which are used at getNextXGridBagConstraints and
710: * getNextYGridBagConstraints.
711: * @deprecated use <code>getLayoutHelper().resetGridCounter</code> instead
712: */
713: public void resetGridCounter() {
714: layoutHelper.resetGridCounter();
715: }
716:
717: /**
718: * Returns a newly created GridBagConstraints with the given values and the values from the
719: * defaultGridBagConstraints for the other parameters.
720: *
721: * @param gridx value to be used for the new constraint
722: * @param gridy value to be used for the new constraint
723: * @return newly created GridBagConstraints with the given values and the values from the
724: * defaultGridBagConstraints for the other parameters
725: * @deprecated use <code>getLayoutHelper().getNewConstraints</code> instead
726: */
727: public GridBagConstraints getNewGridBagConstraints(int gridx,
728: int gridy) {
729: return (GridBagConstraints) (layoutHelper.getNewConstraints(
730: gridx, gridy));
731: }
732:
733: /**
734: * Returns a newly created GridBagConstraints with the given values and the values from the
735: * defaultGridBagConstraints for the other parameters.
736: *
737: * @param gridx value to be used for the new constraint
738: * @param gridy value to be used for the new constraint
739: * @param gridwidth value to be used for the new constraint
740: * @param gridheight value to be used for the new constraint
741: * @return newly created GridBagConstraints with the given values and the values from the
742: * defaultGridBagConstraints for the other parameters
743: * @deprecated use <code>getLayoutHelper().getNewConstraints</code> instead
744: */
745: public GridBagConstraints getNewGridBagConstraints(int gridx,
746: int gridy, int gridwidth, int gridheight) {
747: return (GridBagConstraints) (layoutHelper.getNewConstraints(
748: gridx, gridy, gridwidth, gridheight));
749: }
750:
751: /**
752: * Returns a newly created GridBagConstraints for the next column of the current layout row.
753: *
754: * @return a newly created GridBagConstraints for the next column of the current layout row
755: *
756: * @deprecated use <code>getLayoutHelper().getNextXConstraints</code> instead
757: */
758: public GridBagConstraints getNextXGridBagConstraints() {
759: return (GridBagConstraints) (layoutHelper.getNextXConstraints());
760: }
761:
762: /**
763: * Returns a newly created GridBagConstraints with column 0 for the next row.
764: *
765: * @return a newly created GridBagConstraints with column 0 for the next row
766: *
767: * @deprecated use <code>getLayoutHelper().getNextYConstraints</code> instead
768: */
769: public GridBagConstraints getNextYGridBagConstraints() {
770: return (GridBagConstraints) (layoutHelper.getNextYConstraints());
771: }
772:
773: /**
774: * Returns a newly created GridBagConstraints with column 0 for the next row using the given
775: * parameters.
776: *
777: * @param gridwidth width for this constraint
778: * @param gridheight height for this constraint
779: * @return a newly created GridBagConstraints with column 0 for the next row using the given
780: * parameters
781: * @deprecated use <code>getLayoutHelper().getNextYConstraints</code> instead
782: */
783: public GridBagConstraints getNextYGridBagConstraints(int gridwidth,
784: int gridheight) {
785: return (GridBagConstraints) (layoutHelper.getNextYConstraints(
786: gridwidth, gridheight));
787: }
788:
789: /**
790: * Start layout determining. If it is needed, a dummy component will be created as first row.
791: * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
792: * "SOUTH" or "SOUTHWEST". The earlier used value "BOTTOM" and the declaration via the IzPack
793: * variable <code>IzPanel.LayoutType</code> are also supported.
794: * @deprecated use <code>getLayoutHelper().startLayout</code> instead
795: */
796: public void startGridBagLayout() {
797: layoutHelper.startLayout(new GridBagLayout());
798: }
799:
800: /**
801: * Complete layout determining. If it is needed, a dummy component will be created as last row.
802: * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
803: * "NORTH" or "NORTHWEST". The earlier used value "TOP" and the declaration via the IzPack
804: * variable <code>IzPanel.LayoutType</code> are also supported.
805: * @deprecated use <code>getLayoutHelper().completeLayout</code> instead
806: */
807: public void completeGridBagLayout() {
808: layoutHelper.completeLayout();
809: }
810:
811: // ------------------- Layout stuff -------------------- END ---
812:
813: // ------------------- Summary stuff -------------------- START ---
814: /**
815: * This method will be called from the SummaryPanel to get the summary of this class which
816: * should be placed in the SummaryPanel. The returned text should not contain a caption of this
817: * item. The caption will be requested from the method getCaption. If <code>null</code>
818: * returns, no summary for this panel will be generated. Default behaviour is to return
819: * <code>null</code>.
820: *
821: * @return the summary for this class
822: */
823: public String getSummaryBody() {
824: return null;
825: }
826:
827: /**
828: * This method will be called from the SummaryPanel to get the caption for this class which
829: * should be placed in the SummaryPanel. If <code>null</code> returns, no summary for this
830: * panel will be generated. Default behaviour is to return the string given by langpack for the
831: * key <code><current class name>.summaryCaption></code> if exist, else the string
832: * "summaryCaption.<ClassName>".
833: *
834: * @return the caption for this class
835: */
836: public String getSummaryCaption() {
837: String caption;
838: if (parent.isHeading(this )
839: && idata.guiPrefs.modifier
840: .containsKey("useHeadingForSummary")
841: && (idata.guiPrefs.modifier.get("useHeadingForSummary"))
842: .equalsIgnoreCase("yes")) {
843: caption = getI18nStringForClass("headline", this .getClass()
844: .getName());
845: } else
846: caption = getI18nStringForClass("summaryCaption", this
847: .getClass().getName());
848:
849: return (caption);
850: }
851:
852: // ------------------- Summary stuff -------------------- END ---
853:
854: // ------------------- Inner classes ------------------- START ---
855: public static class Filler extends JComponent {
856:
857: private static final long serialVersionUID = 3258416144414095153L;
858:
859: }
860:
861: // ------------------- Inner classes ------------------- END ---
862:
863: /**
864: * Returns whether this panel will be hidden general or not.
865: * A hidden panel will be not counted in the step counter and
866: * for panel icons.
867: * @return whether this panel will be hidden general or not
868: */
869: public boolean isHidden() {
870: return hidden;
871: }
872:
873: /**
874: * Set whether this panel should be hidden or not.
875: * A hidden panel will be not counted in the step counter and
876: * for panel icons.
877: * @param hidden flag to be set
878: */
879: public void setHidden(boolean hidden) {
880: this .hidden = hidden;
881: }
882:
883: /**
884: * Returns the used layout helper. Can be used in a derived class
885: * to create custom layout.
886: * @return the used layout helper
887: */
888: public LayoutHelper getLayoutHelper() {
889: return layoutHelper;
890: }
891:
892: /**
893: * @return the metadata
894: */
895: public Panel getMetadata() {
896: return this .metadata;
897: }
898:
899: /**
900: * @param p the metadata to set
901: */
902: public void setMetadata(Panel p) {
903: this.metadata = p;
904: }
905: }
|